txnBegin
Open a transaction with an id you generate, and a timeout the server may lower.
txnBegin(request: TxnBeginRequest): Promise<TxnBeginResponse>Parameters
txnIdUUID bytesrequiredThe id you generate, with the SDK's id helper.
timeoutSecondsintegerrequiredHow long the server holds it open. Exceeding it is TransactionTimeout and the transaction is gone — the writes inside it did not land.
actAsActAs | nulloptionalRun the transaction as another space.
Returns
txnIdUUID bytesalwaysEchoed back.
timeoutSecondsintegeralwaysThe timeout the server actually granted — which may be lower than you asked for. Schedule your own deadline from this value, not from the one you sent.
startedAtUnixNanos64-bit integeralwaysWhen the server opened it.
Example
import { newId, EncodeBuilder } from "@brain-db/sdk";
const txnId = newId();
await client.txnBegin({ txnId, timeoutSeconds: 30 });
const req = new EncodeBuilder("Priya moved to Lisbon.").build();
await client.encode({ ...req, txnId });
await client.txnCommit({ txnId });HTTP has no transactions
The HTTP edge exposes no transaction routes. Each HTTP verb is its own unit. If several writes must land together, you need the wire client — see Wire client.
Joining writes to it
Every mutating wire request type carries a txnId field. Setting it is what
puts the write inside the transaction.
The encode, recall and forget builders all leave txnId null and offer no
method to change it. Build the request, then set the field before sending.
A write you believe is in a transaction but whose txnId is null lands
immediately and is not rolled back by an abort.
Was this page helpful?