refactor: Centralize database session management in a shared dependency module
This commit is contained in:
13
routes/dependencies.py
Normal file
13
routes/dependencies.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from collections.abc import Generator
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from config.database import SessionLocal
|
||||
|
||||
|
||||
def get_db() -> Generator[Session, None, None]:
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
Reference in New Issue
Block a user