This commit is contained in:
2026-06-06 23:54:11 +08:00
commit 33639129b1
58 changed files with 10309 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
from __future__ import annotations
import sqlite3
from collections.abc import Generator
from contextlib import contextmanager
from .settings import DATABASE_PATH, ensure_runtime_dirs
@contextmanager
def get_connection() -> Generator[sqlite3.Connection, None, None]:
ensure_runtime_dirs()
connection = sqlite3.connect(DATABASE_PATH)
connection.row_factory = sqlite3.Row
connection.execute("PRAGMA foreign_keys = ON")
try:
yield connection
finally:
connection.close()