-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_tables.py
47 lines (39 loc) · 1.66 KB
/
example_tables.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
from LambdaQuery import *
from datetime import timedelta
class School(Columns):
table = Table("school", 'sc')
def __init__(self):
School.makeTable()
self.baseExpr("school_code", 'code', primary=True)
self.baseExpr("name", 'name')
self.baseExpr("campus", "campus")
class Department(Columns):
table = Table("department", "dept")
def __init__(self):
Department.makeTable()
self.baseExpr("dept_code", 'code', primary=True)
self.baseExpr("school_code", 'sc_code', foreign=School)
self.baseExpr("name", "name")
class Program(Columns):
table = Table("program", 'prog')
def __init__(self):
Program.makeTable()
self.baseExpr("prog_code", 'code', primary=True)
self.baseExpr("school_code", 'sc_code', foreign=School)
self.baseExpr("title", "title")
self.baseExpr("degree", 'degree')
class Course(Columns):
table = Table("course", "course")
def __init__(self):
Course.makeTable()
self.baseExpr("course_code", 'no', primary=True)
self.baseExpr("dept_code", 'dept_code', foreign=Department)
self.baseExpr("description", "description")
self.baseExpr("title", "title")
self.baseExpr("credits", "credits")
# ============================================================================
# instantiate all classes so that the primary and foreign keys are all defined
# ============================================================================
for colclass in [subcls for subcls in Columns.__subclasses__()] \
+ [subsubcls for subcls in Columns.__subclasses__() for subsubcls in subcls.__subclasses__()]:
colclass()