SurrealTransaction represents an in-progress transaction. It is itself a queryable, so the CRUD builders are available scoped to the transaction. Transactions are started with the extension functions on a session and require the WebSocket transport.
Source: surrealdb.kotlin
session.transaction { }
Runs the block against a new SurrealTransaction, committing it if the block returns normally and cancelling it if the block throws.
| Parameter | Type | Description |
|---|---|---|
block | suspend SurrealTransaction.() -> Unit | The operations to run inside the transaction. |
Returns: Unit
session.beginTransaction()
Begins a transaction explicitly and returns a SurrealTransaction for manual commit or cancel.
Returns: SurrealTransaction
Methods
.commit()
Commits the transaction, persisting all its operations.
Returns: Unit
.cancel()
Cancels the transaction, discarding all its operations.
Returns: Unit
Properties
| Property | Type | Description |
|---|---|---|
txnId | String | The transaction's identifier. |