Getting Started

Tutorial: Building with CleaveDB

Exclusive Bonds

In many domain models, a document can only hold one active relationship of a given type at any time. For example, a user may only have one "primary payment method" or one "active team role". Rather than manually severing old bonds before creating new ones, CleaveQL offers the EXCLUSIVELY modifier on BOND.

Enforcing an exclusive bond

Append EXCLUSIVELY after your relationship label:

CleaveQLExample · Assign an exclusive role
BOND "users:bob" TO "roles:lead" AS "assigned_role" EXCLUSIVELY

If Bob previously had an "assigned_role" bond pointing to another role document, CleaveDB severs that previous bond atomically before establishing the new edge to roles:lead.

Switching primary resources

Exclusive bonds simplify status toggling and primary pointer management across collections:

CleaveQLExample · Update primary payment card
BOND "users:jane" TO "cards:card_774" AS "primary_card" EXCLUSIVELY

Guarantees that Jane never has multiple primary cards, preventing race conditions without requiring application-side locks.