Spaces:
Runtime error
Runtime error
Download db.js from Brozy123/LineUp-Bot: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/Brozy123/LineUp-Bot/resolve/d7287468e78b0485df94de132afb92bfc4b1a1e5/db.js
- Command line
-
hf download hf://spaces/Brozy123/LineUp-Bot@d7287468e78b0485df94de132afb92bfc4b1a1e5/db.js
-
curl -L -o db.js https://huggingface.co/spaces/Brozy123/LineUp-Bot/resolve/d7287468e78b0485df94de132afb92bfc4b1a1e5/db.js
1.13 kB
| ; | |
| const Database = require("better-sqlite3"); | |
| const path = require("path"); | |
| const dbPath = path.resolve(__dirname, "bot_data.db"); | |
| const db = new Database(dbPath); | |
| // Initialize tables | |
| db.exec(` | |
| CREATE TABLE IF NOT EXISTS rosters ( | |
| id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| team TEXT NOT NULL, | |
| user_tag TEXT NOT NULL, | |
| role TEXT NOT NULL, | |
| added_at TEXT NOT NULL DEFAULT (datetime('now')) | |
| ); | |
| CREATE INDEX IF NOT EXISTS idx_rosters_team ON rosters(team); | |
| `); | |
| module.exports = { | |
| addRoster(team, userTag, role) { | |
| const stmt = db.prepare("INSERT INTO rosters (team, user_tag, role) VALUES (?, ?, ?)"); | |
| stmt.run(team, userTag, role); | |
| }, | |
| getRosters() { | |
| const rows = db.prepare("SELECT * FROM rosters ORDER BY team, role").all(); | |
| // Group by team | |
| const teams = {}; | |
| rows.forEach(row => { | |
| if (!teams[row.team]) teams[row.team] = []; | |
| teams[row.team].push({ | |
| user: row.user_tag, | |
| role: row.role, | |
| addedAt: row.added_at | |
| }); | |
| }); | |
| return teams; | |
| }, | |
| getAllRaw() { | |
| return db.prepare("SELECT * FROM rosters").all(); | |
| } | |
| }; |