Tutorial: Building with CleaveDB
Cross-Bucket Patterns
In relational databases, querying across different tables requires foreign key constraints, index lookups, and multi-table joins. In CleaveDB, document bonds are bucket-qualified memory pointers (e.g. "staff:ana" to "places:mnl"). FIND PATTERN traverses seamlessly across different bucket collections without schema barriers.
Connecting two different buckets
Consider a relationship between staff members and geographic places:
-- Bond staff member to a location:
BOND "staff:ana" TO "places:mnl" AS "lives_in"
-- Query across buckets:
FIND PATTERN staff AS s LINKED VIA "lives_in" TO places AS pCleaveDB inspects the staff bucket, dereferences the lives_in bond pointer into the places bucket, and returns paired subgraphs: s = Ana, p = Manila.
Multi-bucket relationship chains
You can chain multiple distinct buckets along a single path:
FIND PATTERN users AS u
LINKED VIA "purchased" TO orders AS o
LINKED VIA "contains" TO products AS p
WHERE p.category = "Electronics" AND u.country = "PH"Here, CleaveDB steps through three completely separate buckets (users, orders, and products). The query optimizer filters candidates by selective conditions on any bucket in the chain and walks intermediate bond pointers with zero join overhead.
Heterogeneous mixed links
Because CleaveDB bonds are polymorphic, different documents within the same bucket can bond to entirely different target buckets under the same or different labels:
FIND PATTERN staff AS a
LINKED VIA "manages" TO staff AS b
LINKED VIA "assigned_to" TO projects AS prj
WHERE prj.status = "active"