Files
idrs-api/app/models.py
T

51 lines
1.8 KiB
Python

import os
from pathlib import Path
from sqlalchemy import Boolean, Column, Integer, String, create_engine, event
from sqlalchemy.orm import declarative_base, sessionmaker
BASE_DIR = Path(__file__).resolve().parent.parent
DB_PATH = Path(os.environ.get("IDRS_DB_PATH", BASE_DIR / "idrs.db"))
ICON_DIR = BASE_DIR / "app" / "static" / "icons"
engine = create_engine(
f"sqlite:///{DB_PATH}",
connect_args={"check_same_thread": False},
pool_pre_ping=True,
)
@event.listens_for(engine, "connect")
def _set_wal(dbapi_connection, connection_record):
cursor = dbapi_connection.cursor()
cursor.execute("PRAGMA journal_mode=WAL")
cursor.close()
SessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False)
Base = declarative_base()
class Token(Base):
__tablename__ = "tokens"
idfToken = Column("idfToken", Integer, primary_key=True)
position = Column("position", Integer, unique=True, nullable=False)
typeBlockchain = Column("typeBlockchain", String, nullable=False)
name = Column("name", String, nullable=False)
symbol = Column("symbol", String, nullable=False)
contractAddr = Column("contractAddr", String, nullable=False)
decimals = Column("decimals", Integer, nullable=False)
iconUrl = Column("iconUrl", String, nullable=False, default="")
filename = Column("filename", String, nullable=False, default="")
is_live = Column("is_live", Boolean, nullable=False, default=True)
class Version(Base):
__tablename__ = "version"
id = Column(Integer, primary_key=True)
idVersion = Column("idVersion", Integer, nullable=False)
appName = Column("appName", String, nullable=False)
acceptableVersion = Column("acceptableVersion", Integer, nullable=False)
latestVersion = Column("latestVersion", Integer, nullable=False)