-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.py
41 lines (28 loc) · 1 KB
/
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
from peewee import Model, SqliteDatabase, BigIntegerField, TextField, DateField, CharField
db = SqliteDatabase('deadlines.sqlite')
def all_subclasses(base: type) -> list[type]:
return [
cls
for sub in base.__subclasses__()
for cls in [sub] + all_subclasses(sub)
]
class BaseModel(Model):
class Meta:
database = db
class Deadline(BaseModel):
user = BigIntegerField(column_name="user", primary_key=True)
subject = TextField(column_name="subject")
task = TextField(column_name="task")
deadline = DateField(column_name="deadline")
time = CharField(column_name="time", max_length=11, null=True) # formats: None, HH:MM, HH:MM-HH:MM
class Meta:
table_name = 'deadlines'
class Subject(BaseModel):
user = BigIntegerField(column_name="user")
subject = TextField(column_name="subject")
class Meta:
table_name = 'subjects'
db.create_tables([
sub for sub in all_subclasses(Model)
if not sub.__name__.startswith('_')
])