1
0
Fork 0
forked from sr2/cloud-api

minor: ruff format

Tabs -> spaces
This commit is contained in:
Chris Milne 2026-06-22 15:04:11 +01:00
parent b2921b73b8
commit fab228bf8f
56 changed files with 3629 additions and 3630 deletions

View file

@ -1,6 +1,7 @@
"""
Database connection and session utilities
"""
from contextlib import contextmanager
from typing import Annotated, Generator
from sqlalchemy import create_engine, StaticPool, Connection
@ -29,6 +30,7 @@ else:
sm = sessionmaker(autocommit=False, expire_on_commit=False, bind=engine)
@contextmanager
def get_db_connection() -> Generator[Connection, None, None]:
with engine.connect() as connection:
@ -38,12 +40,15 @@ def get_db_connection() -> Generator[Connection, None, None]:
connection.rollback()
raise
def _get_db_connection() -> Generator[Connection, None]:
with get_db_connection() as connection:
yield connection
DbConnection = Annotated[Connection, Depends(_get_db_connection)]
@contextmanager
def get_db_session() -> Generator[Session, None, None]:
session = sm()
@ -60,4 +65,5 @@ def _get_db_session() -> Generator[Session, None]:
with get_db_session() as session:
yield session
DbSession = Annotated[Session, Depends(_get_db_session)]