Update public source
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[3]
|
||||
DEFAULT_DATABASE_PATH = PROJECT_ROOT / "database" / "wifi.sqlite3"
|
||||
|
||||
|
||||
def connect_database(path: Path | None = None) -> sqlite3.Connection:
|
||||
database_path = path or DEFAULT_DATABASE_PATH
|
||||
|
||||
if not database_path.is_file():
|
||||
raise FileNotFoundError(f"Database not found: {database_path}")
|
||||
|
||||
conn = sqlite3.connect(database_path)
|
||||
conn.row_factory = sqlite3.Row
|
||||
conn.execute("PRAGMA foreign_keys=ON")
|
||||
conn.execute("PRAGMA busy_timeout=5000")
|
||||
return conn
|
||||
Reference in New Issue
Block a user