-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
66 lines (58 loc) · 2.1 KB
/
models.py
File metadata and controls
66 lines (58 loc) · 2.1 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
from sqlalchemy import Integer
from sqlalchemy import Float
from sqlalchemy import String
from sqlalchemy import DateTime
from sqlalchemy import ForeignKey
from sqlalchemy.sql.functions import current_timestamp
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import mapped_column
Base = declarative_base()
class UserDb(Base):
__tablename__ = "users"
id = mapped_column("id", Integer, primary_key=True, autoincrement=True)
name = mapped_column("name", String)
surname = mapped_column("surname", String)
email = mapped_column("email", String, unique=True)
password = mapped_column("password", String)
updated_at = mapped_column(
"updated_at",
DateTime(),
server_default=current_timestamp(),
server_onupdate=current_timestamp(),
)
created_at = mapped_column(
"created_at", DateTime(), server_default=current_timestamp()
)
# one to one relationship
class TaxAccountDb(Base):
__tablename__ = "tax_accounts"
id = mapped_column(
"id", Integer, ForeignKey("users.id"), index=True, primary_key=True
)
rate = mapped_column("rate", Float(precision=2))
updated_at = mapped_column(
"updated_at",
DateTime(),
server_default=current_timestamp(),
server_onupdate=current_timestamp(),
)
created_at = mapped_column(
"created_at", DateTime(), server_default=current_timestamp()
)
# one to many relationship
class SalaryDb(Base):
__tablename__ = "salaries"
id = mapped_column("id", Integer(), primary_key=True, autoincrement=True)
user_id = mapped_column("user_id", Integer(), ForeignKey("users.id"))
amount = mapped_column("amount", Float(precision=2))
amount_hours = mapped_column("amount_hours", Float(precision=1))
salary_date = mapped_column("salary_date", DateTime())
updated_at = mapped_column(
"updated_at",
DateTime(),
server_default=current_timestamp(),
server_onupdate=current_timestamp(),
)
created_at = mapped_column(
"created_at", DateTime(), server_default=current_timestamp()
)