Tutorial: Building with CleaveDB
MATCH & VIA — Cypher-Style & Pattern Queries
In CleaveQL, graph pattern matching allows you to search for structural shapes and relationships across multiple documents and buckets. CleaveDB supports two expressive notations for pattern matching: Cypher-like ASCII arrow syntax with MATCH, and conversational natural language patterns with LINKED VIA.
Cypher-style MATCH queries
The MATCH command defines node variables as (alias FROM bucket) and bonds with bracketed arrow syntax -["label"]->:
MATCH (u FROM users)-["friend"]->(f FROM users)
WHERE f.age > 20This resolves subgraphs across the graph and returns all matching pairs, mapping each alias (u and f) to its respective JSON document.
Pattern traversal with LINKED VIA
You can also express pattern queries using the conversational LINKED VIA clause with FIND PATTERN. Specify each node with AS alias and connect them via their bond label:
FIND PATTERN staff AS x LINKED VIA "manages" TO staff AS yBoth MATCH and LINKED VIA target the same underlying graph traversal execution engine; choose whichever style reads most cleanly for your team.
Edge directions with VIA
The VIA syntax supports three distinct edge orientations:
| Direction | Syntax | Meaning |
|---|---|---|
| Outgoing | LINKED VIA "manages" TO staff AS y | x manages y (points forward) |
| Incoming | LINKED VIA "manages" FROM staff AS boss | boss manages x (points backward) |
| Undirected | LINKED VIA "peer" WITH staff AS y | Mutual bond in either direction |
Multi-hop patterns across buckets
Chain multiple relationship edges and filter by alias properties:
FIND PATTERN staff AS a
LINKED VIA "manages" TO staff AS b
LINKED VIA "mentors" TO staff AS c
WHERE a.department = "Engineering"Or equivalently with MATCH:
MATCH (u FROM users)-["friend"]->(f FROM users)-["owns"]->(d FROM docs)
WHERE u.name = "Alice"