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.
let tx = db.begin().await?;
// tx.query(...), .select(), .create(), .insert(), .upsert(), .update(), .delete() .commit()
tx.commit().await? applies every statement run on the handle and returns ownership of the underlying Surreal client so the connection can run further work outside the transaction.
// let db = tx.commit().await?; .cancel()
tx.cancel().await? rolls back the transaction and also returns the Surreal client for reuse.
// let db = tx.cancel().await?;For a broader discussion and more detailed examples, see the concept page on Manual transactions.