-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.ts
39 lines (35 loc) · 965 Bytes
/
db.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('bean.db');
db.serialize(() => {
try {
console.info('Creating tables...')
db.run(`
CREATE TABLE ctfs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(64) UNIQUE,
start DATETIME,
end DATETIME,
url TEXT
);
`, () => {/* table exists*/});
db.run(`
CREATE TABLE categories (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(64) UNIQUE
);
`, () => {/* table exists*/});
db.run(`
CREATE TABLE chals (
id INTEGER PRIMARY KEY AUTOINCREMENT,
ctf INTEGER NOT NULL,
name VARCHAR(64) NOT NULL,
category INTEGER NOT NULL,
points INTEGER NOT NULL,
done BOOLEAN DEFAULT 0,
FOREIGN KEY (ctf) REFERENCES ctfs (id),
FOREIGN KEY (category) REFERENCES categories (id)
);
`, () => {/* table exists*/});
} catch (e) {console.log(e)}
});
export default db;