-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
58 lines (47 loc) · 1.7 KB
/
example.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
52
53
54
55
56
57
58
from enum import Enum
import cuneiform as cf
cf.configure(db="ozee", user="ozee", password="ozee")
class CompanyType(Enum):
GmbH = 1
AG = 2
KG = 3
other = 4
class Town(cf.Model):
name = cf.Field(str)
class Address(cf.Model):
street = cf.Field(str)
house_number = cf.Field(int) # jaja, eigentlich str..
post_code = cf.Field(str, min_length=5, max_length=5)
town = cf.Field(Town)
class Customer(cf.Model):
name = cf.Field(str)
type = cf.Field(CompanyType, default=None)
addr = cf.Field(Address, default=None)
if __name__ == "__main__":
s = Town(name="Stuttgart")
ka = Town(name="Karlsruhe")
solute_addr = Address(street="Zeppelinstraße", house_number=15, post_code="76137", town=ka)
jo_addr = Address(street="Verschlusssache", house_number=23, post_code="70372", town=s)
Customer(name="Jonathan, Inc.", type=CompanyType.KG, addr=jo_addr).save()
solute = Customer(name="solute", type=CompanyType.GmbH, addr=solute_addr)
solute.save()
print("All customers:", list(Customer.select()))
print("All customers in KA:", list(Customer.select(where=Customer.addr.town.name == "Karlsruhe")))
print("All customers in KA, differently:", list(Customer.select(where=Customer.addr.town == ka)))
print(
"Complex, pointless query:",
list(
Customer.select(
where=(Customer.addr.town.name == "Karlsruhe") | (Customer.type == CompanyType.AG),
),
),
)
print(
"Reverse query:",
list(
Address.select(
where=Address.customers.name == "solute",
),
),
)
print("All customers of solute addr:", solute_addr.customers)