ctrlcent / app /database.py
kacapower's picture
Create app/database.py
f212b2a verified
raw
history blame contribute delete
529 Bytes
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import declarative_base, sessionmaker
# Pointing to the temporary Docker directory
DB_DIR = "/code/data"
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/lexical.db"
engine = create_engine(
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()