import aiosqlite from config import DB_PATH _db: aiosqlite.Connection | None = None async def get_db() -> aiosqlite.Connection: global _db if _db is None: _db = await aiosqlite.connect(DB_PATH) return _db async def init_db(): db = await get_db() # Tabellen folgen, sobald die ersten Features stehen. await db.commit() async def close_db(): global _db if _db is not None: await _db.close() _db = None def _row_to_dict(row, cursor): columns = [d[0] for d in cursor.description] return dict(zip(columns, row))