Refactor backend to use request-scoped SQLite connections
This commit is contained in:
@@ -125,3 +125,18 @@ async def init_db(db: aiosqlite.Connection) -> None:
|
||||
await db.executescript(statement)
|
||||
await db.commit()
|
||||
log.info("database_schema_ready")
|
||||
|
||||
|
||||
async def open_db(database_path: str) -> aiosqlite.Connection:
|
||||
"""Open a new application SQLite connection with the standard settings.
|
||||
|
||||
Args:
|
||||
database_path: Path to the BanGUI SQLite database.
|
||||
|
||||
Returns:
|
||||
A configured :class:`aiosqlite.Connection` instance.
|
||||
"""
|
||||
db = await aiosqlite.connect(database_path)
|
||||
db.row_factory = aiosqlite.Row
|
||||
await db.execute("PRAGMA foreign_keys=ON;")
|
||||
return db
|
||||
|
||||
Reference in New Issue
Block a user