generated from Luis/nextjs-python-web-template
Co-authored-by: sara-pervana <saramakishti@gmail.com> Co-authored-by: ui-asset-bot <ui-asset-bot@gchq.icu> Co-authored-by: Onur Arslan <runoxa@hotmail.com> Co-authored-by: Arslan, Erdem <erdem.arslan@valtech.com> Co-authored-by: Luis-Hebendanz <consulting@qube.email> Reviewed-on: #25 Co-authored-by: Georg-Stahn <g.stahn@campus.tu-berlin.de> Co-committed-by: Georg-Stahn <g.stahn@campus.tu-berlin.de>
23 lines
601 B
Python
23 lines
601 B
Python
from typing import Generator
|
|
|
|
from sqlalchemy import create_engine
|
|
|
|
# from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import Session, declarative_base, sessionmaker
|
|
|
|
URL = "sqlite:///./sql_app.db"
|
|
|
|
engine = create_engine(URL, connect_args={"check_same_thread": False})
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
Base = declarative_base()
|
|
|
|
|
|
# Dependency to start a clean thread of the db
|
|
def get_db() -> Generator[Session, None, None]:
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|