-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql.py
71 lines (54 loc) · 1.58 KB
/
sql.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import sqlite3
from entity.customer import Customer
import os
conn = sqlite3.connect('labelA.db')
cursor = conn.cursor()
if os.path.isfile('labelA.db') == False :
create_db('labelA.db')
print("db created")
else :
print( "db already exists")
def create_db() :
cursor.execute("""CREATE TABLE customer (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
email TEXT,
password TEXT,
created date
)""")
cursor.execute("""CREATE TABLE order (
id INTEGER PRIMARY KEY AUTOINCREMENT,
date TEXT,
status TEXT,
customerId INTEGER,
FORGEIN KEY(customerId) REFERENCES customer(id)
)""")
cursor.execute("""CREATE TABLE delivery (
id INTEGER PRIMARY KEY AUTOINCREMENT,
pref_date datetime,
orderId INTEGER,
FORGEIN KEY(orderId) REFERENCES order(id)
)""")
cursor.execute("""CREATE TABLE cart (
id INTEGER PRIMARY KEY AUTOINCREMENT,
pref_date datetime,
orderId INTEGER,
FORGEIN KEY(orderId) REFERENCES order(id)
)""")
cursor.execute("""CREATE TABLE order_product (
id INTEGER PRIMARY KEY AUTOINCREMENT,
orderId INTEGER,
productId INTEGER,
quantity INTEGER,
FORGEIN KEY(orderId) REFERENCES order(id),
FORGEIN KEY(productId) REFERENCES product(id)
)""")
cursor.execute("""CREATE TABLE product (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
price INTEGER,
description TEXT,
stock INTEGER
)""")
conn.commit()
conn.close()