• Start

Languages

/

Rust

/

Methods

begin

The .begin() method on the SurrealDB Rust SDK client starts a multi-statement transaction and returns a handle for running queries, commits, and rollbacks.

Starts a transaction. The connection is taken into a Transaction that exposes the same query and CRUD entry points as Surreal (scoped to the transaction) plus commit() and cancel().

Note that this method takes by value (taking a self), which is then passed on to the Transaction. The .commit() and .cancel() methods are used to finalise the transaction and return the Surreal client for reuse.

Method Syntax

let tx = db.begin().await?;
// tx.query(...), .select(), .create(), .insert(), .upsert(), .update(), .delete()

// Get the connection back
// let db = tx.commit().await?;
// let db = tx.cancel().await?;

For a broader discussion and more detailed examples, see the concept page on Manual transactions.

Was this page helpful?