Files
wgBill/backend/app/db.py
T
dodox d97aac0e17 Initial scaffold: Flask/SQLite backend, React/Vite PWA frontend
Backend: receipt upload -> LLM vision extraction (OpenAI-compatible,
provider-agnostic), item review/edit, per-group splitting against
Cospend projects/members, highlight+upload via WebDAV, public share
link, bill creation via Cospend's OCS API (verified against real
source, not just doc summaries).

Frontend: capture -> review -> group -> summary flow as an installable
PWA.

install.sh / run.sh (venv + npm, tmux session) instead of Docker, per
the ~/Projects/gain pattern.
2026-08-30 15:02:18 +02:00

24 lines
658 B
Python

import os
import sqlite3
_SCHEMA_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "schema.sql")
_db_path: str | None = None
def init_db(database_path: str) -> None:
global _db_path
_db_path = database_path
os.makedirs(os.path.dirname(database_path), exist_ok=True)
with get_conn() as conn, open(_SCHEMA_PATH) as f:
conn.executescript(f.read())
def get_conn() -> sqlite3.Connection:
if _db_path is None:
raise RuntimeError("init_db() must be called before get_conn()")
conn = sqlite3.connect(_db_path)
conn.row_factory = sqlite3.Row
conn.execute("PRAGMA foreign_keys = ON")
return conn