First commit

This commit is contained in:
2025-05-05 14:01:08 -05:00
parent d93cab7149
commit 2ad1d713cb
16 changed files with 396 additions and 0 deletions

26
src/utils/database.py Normal file
View File

@@ -0,0 +1,26 @@
import aiosqlite
import os
from dotenv import load_dotenv
load_dotenv()
DATABASE_PATH = os.getenv("DATABASE_PATH", "users.db")
# Ensure the directory for the database exists
db_dir = os.path.dirname(DATABASE_PATH)
if db_dir and not os.path.exists(db_dir):
print(f"Creating directory for database: {DATABASE_PATH}")
os.makedirs(db_dir, exist_ok=True)
async def get_db():
async with aiosqlite.connect(DATABASE_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