Atomic & Contexts — Aquilia Documentation
Comprehensive guide and documentation for Atomic & Contexts in the Aquilia framework. View API reference, examples, and implementation patterns.
Docs / Models / Transactions Transactions: Atomic Contexts Aquilia transaction manager supports decorators, context blocks, explicit isolation levels, read-only routing, watchdog timeout constraints, and durability safety checks. Atomic Usage Provide transaction safety with atomic context blocks or decorators: from aquilia.models.transactions import atomic # Context Manager async with atomic(): user = await User.create(name="Alice") await Profile.create(user=user.id) # Decorator @atomic() async def make_purchase(user_id, item_id): await User.objects.filter(id=user_id).update(balance=F("balance") - 10) await Order.create(user_id=user_id, item_id=item_id) Advanced Options Isolation Levels Configure SQL isolation level on PostgreSQL or MySQL: # Supports: READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE async with atomic(isolation="SERIALIZABLE"): ... Read-Only Transactions On SQLite, readonly=True routes queries to a reader connection pool, avoiding locking contentions with the database writer: async with atomic(readonly=True): users = await User.objects.all() Watchdog Timeout Cancel the block and trigger a rollback if execution exceeds the configured duration: # Raises QueryFault if block takes longer than 5 seconds async with atomic(timeout=5.0): await long_running_query() Durability Safety Use durable=True to ensure this transaction block is strictly the outermost block, preventing nesting: async with atomic(durable=True): # Fails with QueryFault if called inside another transaction block ... Many-to-Many Operations Savepoints & Nesting )
Go to Homepage