Brain Docs

Reference

TypeScript SDKInstallationHTTP clientWire client
txnBegintxnCommittxnAbort
ErrorsRetriesPagination
Brain/Docs
✦ ASKBrain on GitHubDashboard
TypeScript SDKTransactionstxnBegin

txnBegin

Open a transaction with an id you generate, and a timeout the server may lower.

PURPOSE

Open a transaction. The id is client-assigned, which is what makes a retry of the begin itself idempotent. Writes join the transaction by carrying that id.

Handshake credentialstable
txnBegin(request: TxnBeginRequest): Promise<TxnBeginResponse>

Parameters

ParameterTypeRequired
txnIdUUID bytesrequired

The id you generate, with the SDK's id helper.

timeoutSecondsintegerrequired

How long the server holds it open. Exceeding it is TransactionTimeout and the transaction is gone — the writes inside it did not land.

actAsActAs | nulloptional

Run the transaction as another space.

Returns

FieldTypePresence
txnIdUUID bytesalways

Echoed back.

timeoutSecondsintegeralways

The 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 integeralways

When 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 builders do not set txnId

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.

See also
txnCommittxnAbort

Was this page helpful?

cancelStream

Stop an in-flight multiplexed stream server-side — abandoning the call does not.

txnCommit

Apply a transaction's writes atomically, and check that every write actually joined it.

On this page

ParametersReturnsExampleJoining writes to it
Suggest an editOpen in Playground