-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_db.py
35 lines (30 loc) · 950 Bytes
/
init_db.py
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
import sqlite3
conn = sqlite3.connect('books.db')
c = conn.cursor()
# Create tables
c.execute('''CREATE TABLE users (
id INTEGER PRIMARY KEY,
discord_id TEXT UNIQUE,
points REAL DEFAULT 0
)''')
c.execute('''CREATE TABLE books (
id INTEGER PRIMARY KEY,
user_id INTEGER,
title TEXT,
length TEXT,
difficulty TEXT,
genre TEXT,
format TEXT,
book_club BOOLEAN,
reread BOOLEAN,
points REAL,
FOREIGN KEY(user_id) REFERENCES users(id)
)''')
c.execute('''CREATE TABLE user_genres (
user_id INTEGER,
genre TEXT,
FOREIGN KEY(user_id) REFERENCES users(id),
UNIQUE(user_id, genre)
)''')
conn.commit()
conn.close()