Tutorial: Building with CleaveDB
Graph Patterns
A single bond answers a one-step question. When the answer lives several links away, FIND PATTERN describes a path across document types and relationship labels. The query below traces a user’s purchase to a product and then to its manufacturer, keeping only paths that lead to Acme Corp.
FIND PATTERN users AS u
LINKED VIA "purchased" TO products AS p
LINKED VIA "manufactured_by" TO brands AS b
WHERE b.name = "Acme Corp"Read the path from its named parts
users AS u names the starting documents. LINKED VIA "purchased" TO products AS p follows the first bond and gives the product node a short alias. The next LINKED VIA clause follows the product’s manufactured_by bond to a brand. Finally, WHERE b.name = "Acme Corp" constrains the brand node, so CleaveDB returns paths that satisfy the full pattern.
Anchor the walk with a selective condition
CleaveDB can use the most restrictive node condition as an anchor, then walk backward along the specified bonds to resolve complete paths. In this example, the brand-name condition gives the engine a focused target. On a dense graph, an unconstrained pattern can create many intermediate paths, so add a meaningful WHERE condition whenever the domain provides one.
