Refactor database sessions into FastAPI dependency
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import Depends
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from database import engine
|
||||
|
||||
|
||||
def get_session():
|
||||
with Session(engine, expire_on_commit=False) as session:
|
||||
yield session
|
||||
|
||||
|
||||
SessionDep = Annotated[
|
||||
Session,
|
||||
Depends(get_session),
|
||||
]
|
||||
Reference in New Issue
Block a user