-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapper.py
105 lines (83 loc) · 3.81 KB
/
mapper.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine, Column, String, Integer, Date
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session
from constants import DatabaseSettings as DBS
Base = declarative_base()
class Client(Base):
"""Wrapper class for the "clients" table in the database."""
__tablename__ = "clients"
id = Column("id", Integer, primary_key=True)
login = Column("login", String, unique=True)
password = Column("password", String)
account_type = Column("account_type", String)
name = Column("name", String)
surname = Column("surname", String)
last_name = Column("last_name", String)
address = Column("address", String)
email = Column("email", String)
phone_number = Column("phone_number", String)
date_of_birth = Column("date_of_birth", Date)
date_of_registration = Column("date_of_registration", Date)
def __init__(self, id, login, password, account_type, name, surname, last_name,
address, email, phone_number, date_of_birth, date_of_registration):
self.id = id
self.login = login
self.password = password
self.account_type = account_type
self.name = name
self.surname = surname
self.last_name = last_name
self.address = address
self.email = email
self.phone_number = phone_number
self.date_of_birth = date_of_birth
self.date_of_registration = date_of_registration
def __repr__(self):
return f"({self.id}, {self.login}, {self.password}, {self.account_type}, {self.surname}, {self.last_name}, {self.address}, {self.email}, {self.phone_number}, {self.date_of_birth}, {self.date_of_registration})"
class Cosmetologist(Base):
"""Wrapper class for the "cosmetologists" table in the database."""
__tablename__ = "cosmetologists"
id = Column("id", Integer, primary_key=True)
name = Column("name", String)
surname = Column("surname", String)
last_name = Column("last_name", String)
address = Column("address", String)
email = Column("email", String)
phone_number = Column("phone_number", String)
date_of_birth = Column("date_of_birth", Date)
date_of_hire = Column("date_of_hire", Date)
def __init__(self, id, name, surname, last_name, address, email, phone_number, date_of_birth,
date_of_hire):
self.id = id
self.name = name
self.surname = surname
self.last_name = last_name
self.address = address
self.email = email
self.phone_number = phone_number
self.date_of_birth = date_of_birth
self.date_of_hire = date_of_hire
def __repr__(self):
return f"({self.id}, {self.name}, {self.surname}, {self.last_name}, {self.address}, {self.email}, {self.phone_number}, {self.date_of_birth}, {self.date_of_hire})"
class Appointment(Base):
"""Wrapper class for the "appointments" table in the database."""
__tablename__ = "appointments"
id = Column("id", Integer, primary_key=True)
id_client = Column("id_client", Integer)
id_cosmetologist = Column("id_cosmetologist", Integer)
price = Column("date_of_appointment", Integer)
rating = Column("rating", Integer)
def __init__(self, id, id_client, id_cosmetologist, price, rating):
self.id = id
self.id_client = id_client
self.id_cosmetologist = id_cosmetologist
self.price = price
self.rating = rating
def __repr__(self):
return f"({self.id}, {self.id_client}, {self.id_cosmetologist}, {self.price}, {self.rating})"
def setup_mapper():
connection_string = f"{DBS.database_type}://{DBS.user}:{DBS.password}@{DBS.host}/{DBS.database_name}"
engine = create_engine(connection_string)
Base.metadata.create_all(bind=engine)
return Session(bind=engine)