-
Notifications
You must be signed in to change notification settings - Fork 3
/
database.py
48 lines (30 loc) · 974 Bytes
/
database.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
import peewee as pw
import json
def set_up_systems_database(db):
print("System database empty!")
print("Creating system table...")
data = {}
with open('systems.json') as f:
data = json.load(f)
with db.atomic():
for key, value in data.items():
System.create(sys_id=key, name=value)
print("Done! Created {} entries".format(System.select().count()))
db = pw.SqliteDatabase('database.db')
class BaseModel(pw.Model):
class Meta:
database = db
class System(BaseModel):
sys_id = pw.IntegerField(primary_key=True)
name = pw.CharField()
class Game(BaseModel):
game = pw.CharField()
system = pw.ForeignKeyField(System, field='sys_id')
publisher = pw.CharField()
developer = pw.CharField()
category = pw.CharField()
year = pw.IntegerField()
# set_up_systems_database(db)
db.create_tables([Game, System])
if (System.select().count() == 0):
set_up_systems_database(db)