aboutsummaryrefslogtreecommitdiff
path: root/src/db.js
diff options
context:
space:
mode:
authorAkshay <[email protected]>2024-11-13 22:34:03 +0000
committerAkshay <[email protected]>2024-11-13 22:34:03 +0000
commitbbe0413ae1aad2516745f6f279225d2aea3555af (patch)
tree609fc751fb153f9fc0e3fbf111b644d5df5b1025 /src/db.js
parent81adffe4c1ecd2f0260ec08e73760505dfe4edaa (diff)
add login and users and all the pizzazz
Diffstat (limited to 'src/db.js')
-rw-r--r--src/db.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/db.js b/src/db.js
new file mode 100644
index 0000000..24bba3d
--- /dev/null
+++ b/src/db.js
@@ -0,0 +1,24 @@
1const { Database } = require("bun:sqlite");
2const db = new Database("readit.db", {
3 strict: true,
4});
5
6db.query(`
7 CREATE TABLE IF NOT EXISTS users (
8 id INTEGER PRIMARY KEY AUTOINCREMENT,
9 username TEXT UNIQUE,
10 password_hash TEXT
11 )
12`).run();
13
14db.query(`
15 CREATE TABLE IF NOT EXISTS subscriptions (
16 id INTEGER PRIMARY KEY AUTOINCREMENT,
17 user_id INTEGER,
18 subreddit TEXT,
19 FOREIGN KEY(user_id) REFERENCES users(id),
20 UNIQUE(user_id, subreddit)
21 )
22`).run();
23
24module.exports = { db };