22 lines
587 B
Python
22 lines
587 B
Python
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
# Dependency mapping for FastAPI
|
|
# Using standard relative path, but easily overridden with env vars later
|
|
SQLALCHEMY_DATABASE_URL = "sqlite:///tapehoard.db"
|
|
|
|
# connect_args={"check_same_thread": False} is required for SQLite in FastAPI
|
|
engine = create_engine(
|
|
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
|
|
)
|
|
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|