• Start

Methods

begin_transaction

The begin_transaction() method for the SurrealDB Mojo SDK starts a session-scoped transaction.

Starts a session-scoped transaction and returns a handle. The handle buffers statements and flushes them on commit().

Method Syntax
client.begin_transaction(session)

Argument

Description

session

An optional session id.

The returned handle exposes:

  • query(query, bindings_json) to buffer a statement.

  • create(thing, content_json) and select(thing) convenience wrappers.

  • commit() to run the buffered statements atomically.

  • cancel() to discard them.

var txn = client.begin_transaction()
_ = txn.query("CREATE person:alice SET age = 30;")
_ = txn.query("CREATE person:bob   SET age = 31;")
txn.commit()
Note

Session transactions run over a stateful WebSocket session. WebSocket support is rolling out. For atomic transactions over HTTP, use transaction_multi().

Was this page helpful?