Skip to main content
Transactions enable you to batch multiple data object and data attribute operations into a single atomic unit. All operations are queued locally and executed in one call, providing both atomicity (all succeed or all fail) and significantly better performance for bulk operations.

Overview

Transactions are especially useful when:
  • Creating many data objects and attributes at once
  • Performing extraction operations that produce multiple related records
  • Needing atomic rollback on failure
  • Optimizing performance for bulk operations

Python Usage

In Python, use the batch_transaction() context manager:

Transaction Operations

The TransactionContext provides accessors that mirror the standard data accessors:

ID Resolution

When you create a data object within a transaction, it returns a record with a temporary ID. You can use this temporary ID to create child objects or attributes within the same transaction. The IDs are resolved to real database IDs when the transaction is committed.

Error Handling

If an exception occurs within the transaction block, all queued operations are discarded:

TypeScript Usage

In TypeScript, use the transaction() method with an async callback:

Performance

Transactions provide significant performance benefits for bulk operations:
  • Without transactions: Each create/update/delete is a separate FFI/WASM call
  • With transactions: All operations are batched into a single call
For operations involving dozens or hundreds of data objects and attributes, transactions can be orders of magnitude faster.

Best Practices

  1. Use transactions for bulk operations: Any time you’re creating more than a few data objects or attributes, wrap them in a transaction.
  2. Keep transactions focused: Don’t mix unrelated operations in the same transaction.
  3. Handle errors: Wrap transaction blocks in try/except (Python) or try/catch (TypeScript) to handle failures gracefully.
  4. Check operation count: Use tx.operation_count (Python) or tx.operationCount (TypeScript) to verify the expected number of operations before committing.