Initial commit: Simple ASM - ARM assembly learning game
10-level progressive game teaching ARM assembly basics: registers, arithmetic, bitwise ops, memory, branching, loops. Vue 3 + FastAPI + SQLite with K8s deployment.
This commit is contained in:
34
backend/database.py
Normal file
34
backend/database.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import aiosqlite
|
||||
import os
|
||||
|
||||
DB_PATH = os.environ.get("DB_PATH", "app.db")
|
||||
|
||||
|
||||
async def get_db():
|
||||
db = await aiosqlite.connect(DB_PATH)
|
||||
db.row_factory = aiosqlite.Row
|
||||
await db.execute("PRAGMA journal_mode=WAL")
|
||||
return db
|
||||
|
||||
|
||||
async def init_db():
|
||||
db = await get_db()
|
||||
await db.executescript("""
|
||||
CREATE TABLE IF NOT EXISTS players (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT UNIQUE NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS progress (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
player_id INTEGER NOT NULL,
|
||||
level_id INTEGER NOT NULL,
|
||||
stars INTEGER NOT NULL DEFAULT 0,
|
||||
code TEXT,
|
||||
completed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (player_id) REFERENCES players(id),
|
||||
UNIQUE (player_id, level_id)
|
||||
);
|
||||
""")
|
||||
await db.commit()
|
||||
await db.close()
|
||||
Reference in New Issue
Block a user