work on new async sqlite3 statistics database

This commit is contained in:
Xevion
2021-01-24 14:23:28 -06:00
parent e9446c00e2
commit 58a97c9a6b

38
bot/stats.py Normal file
View 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())