Skip to content

transaction

Transaction management for database controllers.

Classes:

Classes

TransactionController

Python
TransactionController(model: type[ModelT], db: DatabaseService)

Handles transaction and session management.

Initialize the transaction controller.

Parameters:

  • model (type[ModelT]) –

    The SQLModel to manage transactions for.

  • db (DatabaseService) –

    The database service instance.

Methods:

Functions

with_session async
Python
with_session[R](operation: Callable[[AsyncSession], Awaitable[R]]) -> R

Execute operation within a session context.

Returns:

  • R

    The result of the operation.

with_transaction async
Python
with_transaction[R](operation: Callable[[AsyncSession], Awaitable[R]]) -> R

Execute operation within a transaction context.

Returns:

  • R

    The result of the operation.

execute_transaction async
Python
execute_transaction(callback: Callable[[], Any]) -> Any

Execute a callback within a transaction.

Returns:

  • Any

    The result of the callback.

safe_get_attr staticmethod
Python
safe_get_attr(obj: Any, attr: str, default: Any = None) -> Any

Safely get attribute from object.

Returns:

  • Any

    The attribute value, or default if not found.