tech-updates / app /db /database.py
HFShishir's picture
Deploy BytePulse AI Backend v1.0
ef58e1a verified
Raw History Blame Contribute Delete
581 Bytes
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, declarative_base
from app.config import settings
# Check if SQLite and configure connect_args
connect_args = {"check_same_thread": False} if settings.DATABASE_URL.startswith("sqlite") else {}
engine = create_engine(
settings.DATABASE_URL,
connect_args=connect_args,
echo=settings.DEBUG
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()