-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_db.py
42 lines (31 loc) · 1013 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
36
37
38
39
40
41
42
from peewee import *
#Create the database
db = SqliteDatabase('trains.db')
#Define the fields. This is defined in the peewee documentation.
class Train(Model):
id = AutoField()
origin = CharField()
destination = CharField()
due = TimeField()
delay = IntegerField()
est = TimeField()
cancelled = BooleanField()
day = CharField()
class Meta:
database = db
#Connect and create the tables
db.connect()
db.create_tables([Train])
#Then it is possible to interact with the database in various ways like so:
#train = Train(origin="LNC", destination="Sheffield", due="17:49", delay=0, est="17:49", cancelled=False,day="monday")
#success = train.save()
#print(success)
#mytrain = Train.get(Train.destination == "Sheffield")
#mytrain.delay = 3
#mytrain.est = "17:33"
#mytrain.save()
for train in Train.select().where(Train.destination == "Sheffield").order_by(Train.due.desc()).limit(1):
train.est = "19:58"
success = train.save()
print(success)
db.close()