• Start

Languages

/

Mojo

/

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)
ArgumentDescription
sessionAn 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()

Was this page helpful?