forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtables.py
More file actions
79 lines (54 loc) · 1.45 KB
/
tables.py
File metadata and controls
79 lines (54 loc) · 1.45 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from enum import Enum
from piccolo.columns import (
JSON,
JSONB,
ForeignKey,
Integer,
Numeric,
Text,
Varchar,
)
from piccolo.columns.readable import Readable
from piccolo.table import Table
###############################################################################
# Simple example
class Manager(Table):
name = Varchar(length=50)
@classmethod
def get_readable(cls) -> Readable:
return Readable(template="%s", columns=[cls.name])
class Band(Table):
name = Varchar(length=50)
manager = ForeignKey(Manager, null=True)
popularity = Integer(default=0)
###############################################################################
# More complex
class Venue(Table):
name = Varchar(length=100)
capacity = Integer(default=0)
class Concert(Table):
band_1 = ForeignKey(Band)
band_2 = ForeignKey(Band)
venue = ForeignKey(Venue)
class Ticket(Table):
price = Numeric(digits=(5, 2))
class Poster(Table, tags=["special"]):
"""
Has tags for tests which need it.
"""
content = Text()
class Shirt(Table):
"""
Used for testing columns with a choices attribute.
"""
class Size(str, Enum):
small = "s"
medium = "m"
large = "l"
size = Varchar(length=1, choices=Size, default=Size.large)
class RecordingStudio(Table):
"""
Used for testing JSON and JSONB columns.
"""
facilities = JSON()
facilities_b = JSONB()