📅  最后修改于: 2022-03-11 14:47:25.093000             🧑  作者: Mango
from decouple import config
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session, declarative_base
from types import SimpleNamespace
SQLALCHEMY_DATABASE_URL = config('SQLALCHEMY_DATABASE_URL')
engine = create_engine(SQLALCHEMY_DATABASE_URL)
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)
session = scoped_session(Session)
Base = declarative_base()
# Note the line below
Base.query = session.query_property()
class User(Base):
__tablename__ = 'user'
id = Column(Integer, primary_key=True)
email = Column(String(250), nullable=False)
password = Column(String(30))
last_login_at = Column(DateTime)
active = Column(Boolean)
confirmed_at = Column(DateTime)
current_login_at = Column(DateTime)
last_login_ip = Column(String(45))
current_login_ip = Column(String(45))
login_count = Column(Integer)