SurrealDB wraps every query RPC in its own implicit BEGIN/COMMIT, so a transaction has to live inside a single multi-statement query. The Mojo SDK gives you two ways to do this.
Atomic multi-statement transactions
transaction_multi takes a list of statements, wraps them in BEGIN TRANSACTION; and COMMIT TRANSACTION;, and sends them as a single atomic query. This works on any transport and is the recommended approach over HTTP.
If any statement fails, the whole transaction is rolled back.
Session transactions
Over a stateful WebSocket session, begin_transaction() returns a handle that buffers statements and flushes them on commit(). The handle exposes query(), create(), select(), commit(), and cancel().
Call cancel() instead of commit() to discard the buffered statements.
Note
See the method reference for transaction_multi and begin_transaction.