-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_init.py
51 lines (37 loc) · 1.08 KB
/
db_init.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
import sqlite3
from models.user import User
from models.post import Post
from models.colonne import Colonne
from models.tableaux import Tableau
def make_dicts(cursor, row):
return dict((cursor.description[idx][0], value)
for idx, value in enumerate(row))
db = sqlite3.connect('.data/db.sqlite')
db.row_factory = make_dicts
cur = db.cursor()
User.create_table(cur)
Post.create_table(cur)
Colonne.create_table(cur)
Tableau.create_table(cur)
users = [
User("Ford", "[email protected]", "12345"),
User("Arthur", "[email protected]", "12345"),
]
#posts = [
# Post(content="Hi!", author_id="[email protected]"),
# Post(content="Don't destroy the earth please!", author_id="[email protected]"),
#]
for user in users:
user.insert(cur)
#for post in posts:
# post.insert(cur)
db.commit()
print("The following users has been inserted into the DB"
" (all the passwords are 12345):")
for user in users:
# uses the magic __repr__ method
print("\t", user)
print()
print("Here are the posts inserted:")
#for post in posts:
# print("\t", post)