27 lines
637 B
Python
27 lines
637 B
Python
from sqlmodel import create_engine, SQLModel, Session
|
|
|
|
from ..model.models import Base
|
|
|
|
SQLALCHEMY_DATABASE_URL = "sqlite:///./gatekeeper.db"
|
|
|
|
engine = create_engine(SQLALCHEMY_DATABASE_URL)
|
|
|
|
def create_db_and_tables():
|
|
SQLModel.metadata.create_all(engine)
|
|
from alembic.config import Config
|
|
from alembic import command
|
|
alembic_cfg = Config("./alembic.ini")
|
|
command.stamp(alembic_cfg, "head")
|
|
|
|
def get_session():
|
|
with Session(engine) as db:
|
|
yield db
|
|
|
|
def get_db_session():
|
|
return Session(engine)
|
|
|
|
def add_and_refresh(db: Session, obj):
|
|
db.add(obj)
|
|
db.commit()
|
|
db.refresh(obj)
|
|
return obj |