Getting Started

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"]->:

CleaveQLExample · Cypher-style friend lookup
MATCH (u FROM users)-["friend"]->(f FROM users)
WHERE f.age > 20

This 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:

CleaveQLExample · Pattern query using LINKED VIA
FIND PATTERN staff AS x LINKED VIA "manages" TO staff AS y

Both 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:

DirectionSyntaxMeaning
OutgoingLINKED VIA "manages" TO staff AS yx manages y (points forward)
IncomingLINKED VIA "manages" FROM staff AS bossboss manages x (points backward)
UndirectedLINKED VIA "peer" WITH staff AS yMutual bond in either direction

Multi-hop patterns across buckets

Chain multiple relationship edges and filter by alias properties:

CleaveQLExample · Multi-hop chain with VIA
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:

CleaveQLExample · Equivalent multi-hop MATCH query
MATCH (u FROM users)-["friend"]->(f FROM users)-["owns"]->(d FROM docs)
WHERE u.name = "Alice"