feat(db): Added DB
This commit is contained in:
1 parent
d719c949e2
commit
544baffba2
2 files changed
+30
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import os
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
DB_PATH = Path(os.environ.get("DB_PATH") or PROJECT_ROOT / "backend.db")
|
||||
|
||||
SCHEMA = """
|
||||
CREATE TABLE IF NOT EXISTS requests (
|
||||
id TEXT PRIMARY KEY,
|
||||
text TEXT NOT NULL,
|
||||
file TEXT NOT NULL DEFAULT '[]',
|
||||
status TEXT NOT NULL DEFAULT 'WAITING',
|
||||
worker INTEGER NOT NULL DEFAULT 0,
|
||||
result TEXT DEFAULT NULL
|
||||
);
|
||||
"""
|
||||
|
||||
|
||||
def init_db() -> Path:
|
||||
DB_PATH.parent.mkdir(parents=True, exist_ok=True)
|
||||
with sqlite3.connect(DB_PATH) as conn:
|
||||
conn.executescript(SCHEMA)
|
||||
conn.commit()
|
||||
return DB_PATH
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"DB initialized: {init_db()}")
|
||||
Whitespace-only changes.
Reference in new issue
Block a user