Transactions​

EdgeQL supports atomic transactions. The transaction API consists of several commands:

start transaction

Start a transaction, specifying the isolation level, access mode (read only vs read write), and deferrability.

declare savepoint

Establish a new savepoint within the current transaction. A savepoint is a intermediate point in a transaction flow that provides the ability to partially rollback a transaction.

release savepoint

Destroys a savepoint previously defined in the current transaction.

rollback to savepoint

Rollback to the named savepoint. All changes made after the savepoint are discarded. The savepoint remains valid and can be rolled back to again later, if needed.

rollback

Rollback the entire transaction. All updates made within the transaction are discarded.

commit

Commit the transaction. All changes made by the transaction become visible to others and will persist if a crash occurs.

Client libraries​

There is rarely a reason to use these commands directly. All EdgeDB client libraries provide dedicated transaction APIs that handle transaction creation under the hood.

TypeScript/JS​

  1. client.transaction(async tx => {
  2. await tx.execute(`insert Fish { name := 'Wanda' };`);
  3. });

Full documentation at Client Libraries > TypeScript/JS;

Python​

  1. async for tx in client.transaction():
  2. async with tx:
  3. await tx.execute("insert Fish { name := 'Wanda' };")

Full documentation at Client Libraries > Python;

Golang​

  1. err := client.Tx(ctx, func(ctx context.Context, tx *Tx) error {
  2. query := "insert Fish { name := 'Wanda' };"
  3. if e := tx.Execute(ctx, query); e != nil {
  4. return e
  5. }
  6. })

Full documentation at Client Libraries > Go.