Getting Started

Tutorial: Building with CleaveDB

BEGIN & COMMIT

The BEGIN and COMMIT commands delimit an atomic transaction block. Operations inside the block are buffered in memory and committed together as a single atomic unit.

Multi-statement transaction block

Use BEGIN TRANSACTION (or simply BEGIN) to initiate the buffer, execute write statements, and finalize with COMMIT:

CleaveQLExample · Coordinated multi-document write
BEGIN TRANSACTION
POUR INTO users "alice" {"money": 50}
POUR INTO users "bob" {"money": 150}
COMMIT

Both documents (alice and bob) enter the database simultaneously. If an error occurs on the second write, the first write is not persisted.

Single-line chained transactions

In CleaveQL, multiple commands can be chained on a single line. This allows sending an entire atomic transaction block in a single network roundtrip:

CleaveQLExample · Single-line transaction chain
BEGIN POUR INTO users "t1" {"name": "T1"} POUR INTO users "t2" {"name": "T2"} COMMIT

Sending transaction blocks as a single command string eliminates network latency roundtrips between individual operations.

Mixing documents, bonds, and updates

A single transaction can compose document creation (POUR), graph bond creation (BOND), and document mutations (CHANGE):

CleaveQLExample · Composite multi-paradigm transaction
BEGIN POUR INTO mix "m3" {"v": 3} BOND "mix:m3" TO "mix:m1" AS "tx" CHANGE mix "m3" SET v TO 4 COMMIT

The document creation, graph bond establishment, and field update all commit in unison.