16 lines
355 B
Python
16 lines
355 B
Python
from typing import Generator
|
|
|
|
from app.db.session import SessionLocal
|
|
|
|
|
|
# Dependency to get DB session
|
|
def get_db() -> Generator:
|
|
"""
|
|
Dependency for getting a database session.
|
|
This function yields a SQLAlchemy session and ensures it's closed after use.
|
|
"""
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close() |