-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialize_db.py
54 lines (41 loc) · 1.31 KB
/
initialize_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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import sqlite3
conn = sqlite3.connect('example.db')
c = conn.cursor()
# Create table
# c.execute('''CREATE TABLE orders
# (text, trans text, symbol text, qty real, price real)''')
# Insert a row of data
# c.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)")
# EXISTING ORDERS
# Create table
c.execute('''CREATE TABLE orders
(order_date, order_number, order_email, color, size, status)''')
# data to be added
purchases = [('2006-01-05',123456,'example@rasa.com','blue', 9, 'shipped'),
('2021-01-05',123457,'me@rasa.com','black', 10, 'order pending'),
('2021-01-05',123458,'me@gmail.com','gray', 11, 'delivered'),
]
# add data
c.executemany('INSERT INTO orders VALUES (?,?,?,?,?,?)', purchases)
# AVAILABLE INVENTORY
# Create table
c.execute('''CREATE TABLE inventory
(size, color)''')
# data to be added
inventory = [(7, 'blue'),
(8, 'blue'),
(9, 'blue'),
(10, 'blue'),
(11, 'blue'),
(12, 'blue'),
(7, 'black'),
(8, 'black'),
(9, 'black'),
(10, 'black')
]
# add data
c.executemany('INSERT INTO inventory VALUES (?,?)', inventory)
# Save (commit) the changes
conn.commit()
# end connection
conn.close()