46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
from sqlalchemy import BigInteger, Column, MetaData, String, Float, Text, Index, Integer
|
|
from sqlalchemy.orm import DeclarativeBase
|
|
from sqlalchemy.orm import sessionmaker
|
|
from sqlalchemy import create_engine
|
|
from src.config import settings
|
|
|
|
class Base(DeclarativeBase):
|
|
metadata = MetaData()
|
|
|
|
class Drug(Base):
|
|
__tablename__ = "drugs"
|
|
|
|
id = Column(BigInteger, primary_key=True, index=True)
|
|
name = Column(String, nullable=False, index=True)
|
|
dosage = Column(Float, nullable=False)
|
|
dosage_unit = Column(String, nullable=False)
|
|
unit_price = Column(Float, nullable=False)
|
|
description = Column(Text, nullable=True)
|
|
|
|
Index(
|
|
"ix_drugs_name_dosage_dosage_unit",
|
|
Drug.name,
|
|
Drug.dosage,
|
|
Drug.dosage_unit,
|
|
unique=True
|
|
)
|
|
|
|
|
|
class Webpage(Base):
|
|
__tablename__ = "webpage"
|
|
|
|
id = Column(String, primary_key=True, index=True)
|
|
n = Column(Integer, index=True)
|
|
description = Column(String)
|
|
|
|
|
|
class UserSession(Base):
|
|
__tablename__ = "user_session"
|
|
|
|
id = Column(BigInteger, primary_key=True, index=True)
|
|
user_id = Column(String, index=True)
|
|
session_id = Column(String)
|
|
|
|
|
|
engine = create_engine(settings.DATABASE_URL)
|
|
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|