You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.5 KiB
54 lines
1.5 KiB
from sqlalchemy import \
|
|
Boolean, Column, DateTime, ForeignKey, Integer, String, Text, UniqueConstraint, \
|
|
text, func, \
|
|
create_engine, inspect, select
|
|
from sqlalchemy.engine import Engine
|
|
from sqlalchemy.orm import relationship, sessionmaker, Session, class_mapper, joinedload, aliased
|
|
from sqlalchemy.orm.attributes import get_history
|
|
from sqlalchemy.orm.query import Query
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.sql.expression import CTE
|
|
from sqlalchemy.sql.functions import ReturnTypeFromArgs
|
|
from sqlalchemy.sql.sqltypes import Numeric
|
|
from typing import Any, Optional, List, Tuple
|
|
|
|
import hra.config as config
|
|
|
|
Base = declarative_base()
|
|
metadata = Base.metadata
|
|
|
|
|
|
_engine: Optional[Engine] = None
|
|
_session: Optional[Session] = None
|
|
flask_db: Any = None
|
|
|
|
def get_engine() -> Engine:
|
|
global _engine
|
|
if _engine is None:
|
|
_engine = create_engine(config.SQLALCHEMY_DATABASE_URI, echo=config.SQLALCHEMY_ECHO)
|
|
return _engine
|
|
|
|
def get_session() -> Session:
|
|
global _session
|
|
if flask_db:
|
|
return flask_db.session
|
|
if _session is None:
|
|
MOSession = sessionmaker(bind=get_engine())
|
|
_session = MOSession()
|
|
return _session
|
|
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = 'users'
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
org = Column(Boolean)
|
|
username = Column(String(80), unique=True, nullable=False)
|
|
passwd = Column(String(80), nullable=False)
|
|
|
|
def __repr__(self):
|
|
return '<User %r>' % self.username
|
|
|
|
|
|
|