mirror of
https://github.com/sfiorini/iptv-server.git
synced 2026-04-11 08:40:44 +00:00
22 lines
674 B
Python
22 lines
674 B
Python
import aiosqlite
|
|
from pathlib import Path
|
|
from src.config import DATABASE_FILENAME, DATA_PATH
|
|
|
|
async def get_db():
|
|
# Build the full database path
|
|
db_path = Path(DATA_PATH) / DATABASE_FILENAME
|
|
|
|
# Ensure the directory exists
|
|
db_path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
async with aiosqlite.connect(db_path) as db:
|
|
# Enable WAL mode for better concurrency
|
|
await db.execute("PRAGMA journal_mode=WAL;")
|
|
await db.execute("""
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
username TEXT PRIMARY KEY,
|
|
hashed_password TEXT
|
|
)
|
|
""")
|
|
await db.commit()
|
|
yield db |