Getting Started

Tutorial: Building with CleaveDB

FIND PATTERN Basics

In CleaveQL, FIND PATTERN matches subgraph paths across buckets and bond edges declaratively. Each document node in the pattern is assigned an alias using AS alias, and connections are defined with LINKED VIA "label".

Two-node pattern

To find all staff members who manage another staff member, declare the starting node and connect it to the target node:

CleaveQLExample · Basic two-node pattern
FIND PATTERN staff AS x LINKED VIA "manages" TO staff AS y

You can also include the optional IN keyword if you prefer conversational phrasing:

CleaveQLExample · Using optional IN keyword
FIND PATTERN IN staff AS x LINKED VIA "manages" TO staff AS y

CleaveDB evaluates the pattern across the graph and returns all matching pairs, mapping each alias (x and y) to its full resolved JSON document.

Filtering aliases with WHERE

You can filter on properties of any node alias anywhere along the pattern:

CleaveQLExample · Pattern with WHERE condition
FIND PATTERN staff AS x LINKED VIA "manages" TO staff AS y WHERE x.role = "lead"

CleaveDB's query planner uses the WHERE condition as an index anchor to filter starting candidates before traversing the bond pointers, maximizing traversal speed.

Chaining multi-node paths

Chain multiple LINKED VIA clauses together to express deeper relationship graphs:

CleaveQLExample · Three-node management & mentorship chain
-- Who does Ana manage that also mentors someone?
FIND PATTERN staff AS a
  LINKED VIA "manages" TO staff AS b
  LINKED VIA "mentors" TO staff AS c

This returns complete 3-node paths matching the shape a → b → c (for example: a = Ana → b = Ben → c = Dee).