-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
52 lines (50 loc) · 1.6 KB
/
db.py
File metadata and controls
52 lines (50 loc) · 1.6 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
import sqlite3
def play_db():
connection = sqlite3.connect('example.db')
cursor = connection.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS users(
user_id TEXT PRIMARY KEY NOT NULL UNIQUE,
user_password TEXT NOT NULL,
user_point INTEGER DEFAULT 0
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS alarms(
alarm_id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id TEXT NOT NULL,
time TEXT,
FOREIGN KEY (user_id) REFERENCES users(user_id)
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS brands(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
brand_name TEXT,
price INTEGER,
UNIQUE(name, brand_name)
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS buy_product(
ids INTEGER PRIMARY KEY AUTOINCREMENT,
user_id TEXT NOT NULL,
brand_id TEXT,
product TEXT,
FOREIGN KEY (user_id) REFERENCES users(user_id)
)
''')
data = [
('5000권','GS25',60), ('10000권','GS25',120),
('5000권','CU',60), ('10000권','CU',120),
('5000권','KAKAO',60), ('10000권','KAKAO',120),
('5000권','OLIVEYOUNG',60), ('10000권','OLIVEYOUNG',120),
('5000권','NAVER',60), ('10000권','NAVER',60),
('5000권','7ELEVEN',60), ('10000권','7ELEVEN',120)
]
for name, brand, price in data:
cursor.execute("INSERT OR IGNORE INTO brands (name, brand_name, price) VALUES (?, ?, ?)",
(name,brand,price))
connection.commit()
connection.close()