Transactions

tortoise.transactions.atomic(connection_name=None)[source]

Transaction decorator.

You can wrap your function with this decorator to run it into one transaction. If error occurs transaction will rollback.

Parameters:
connection_name=None

name of connection to run with, optional if you have only one db connection

Return type:

Callable[[Callable[…, Any]], Callable[…, Any]]

tortoise.transactions.in_transaction(connection_name=None)[source]

Transaction context manager.

You can run your code inside async with in_transaction(): statement to run it into one transaction. If error occurs transaction will rollback.

Parameters:
connection_name=None

name of connection to run with, optional if you have only one db connection

Return type:

TransactionContext