-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmodels.py
More file actions
33 lines (24 loc) · 921 Bytes
/
models.py
File metadata and controls
33 lines (24 loc) · 921 Bytes
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
import datetime
from sqlalchemy import Column, String, Integer, create_engine, DateTime, Float
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
engine = create_engine(
"mysql+pymysql://root:qwerty@localhost:3306/company"
)
Session = sessionmaker(bind=engine)
Base = declarative_base(bind=engine)
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True, autoincrement=True)
first_name = Column(String(50), nullable=False)
last_name = Column(String(50), nullable=False)
email = Column(String(50), nullable=False, unique=True)
salary = Column(Float, default=0, nullable=False)
creation_date = Column(
DateTime,
default=datetime.datetime.now,
nullable=False
)
def __repr__(self):
return f"User({self.first_name}, {self.last_name}, {self.email})"
Base.metadata.create_all()