mirror of
https://github.com/Xevion/unbelievaselfbot.git
synced 2025-12-09 18:08:54 -06:00
work on new async sqlite3 statistics database
This commit is contained in:
38
bot/stats.py
Normal file
38
bot/stats.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import sqlite3
|
||||
|
||||
import aiosqlite
|
||||
|
||||
from bot import constants
|
||||
|
||||
logger = logging.getLogger(__file__)
|
||||
logger.setLevel(constants.LOGGING_LEVEL)
|
||||
|
||||
|
||||
class StatsHandler(object):
|
||||
def __init__(self, db: aiosqlite.Connection) -> None:
|
||||
self.db = db
|
||||
|
||||
@classmethod
|
||||
async def create(cls) -> 'StatsHandler':
|
||||
"""Factory method for creating StatsHandler objects."""
|
||||
db = await aiosqlite.connect(constants.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES)
|
||||
stats = StatsHandler(db)
|
||||
# await stats.construct()
|
||||
await db.commit()
|
||||
return stats
|
||||
|
||||
async def construct(self) -> None:
|
||||
"""Construct the database."""
|
||||
await self.db.execute('''CREATE TABLE IF NOT EXISTS change
|
||||
(id INTEGER PRIMARY KEY,
|
||||
self BOO
|
||||
''')
|
||||
|
||||
async def record_change(self) -> None:
|
||||
pass
|
||||
|
||||
aiosqlite.register_adapter(bool, int)
|
||||
aiosqlite.register_converter("BOOLEAN", lambda v: bool(int(v)))
|
||||
asyncio.run(StatsHandler.create())
|
||||
Reference in New Issue
Block a user