Cypher Query Language

Anvil implements the Cypher query language with a hand-written lexer, recursive descent parser, cost-based optimizer, and Volcano-model executor. In addition to standard Cypher for property graphs, Anvil extends the language with native document operations, stored functions, triggers, row-level security, and graph-document synchronization.

Quick Example

-- Query with pattern matching
MATCH (p:Person)-[r:FRIEND]->(friend:Person)
WHERE p.name = "Alice"
RETURN p.name, friend.name, r.since

Supported Clauses

ClauseDescription
MATCHPattern match against the graph
OPTIONAL MATCHMatch with null padding for missing patterns
WHEREFilter matched results
RETURNProject results with aliases
WITHChain query stages, project intermediate results
ORDER BYSort results (ASC / DESC)
SKIP / LIMITPaginate results
UNWINDExpand a list into rows
CREATECreate nodes and relationships
MERGEMatch or create a pattern
SETUpdate properties or add labels
REMOVERemove properties or labels
DELETE / DETACH DELETEDelete nodes and relationships
UNION / UNION ALLCombine result sets
CALL ... YIELDInvoke stored functions
FOREACHIterate and perform updates

Anvil Extensions

Beyond standard Cypher, Anvil adds first-class support for documents, stored functions, triggers, row-level security policies, sync rules, and query analysis. These extensions integrate seamlessly - you can reference documents in graph queries, trigger document writes from graph events, and synchronize data between both models.

ExtensionDescription
CREATE / MATCH / UPSERT / DELETE DOCUMENTNative document store operations inside Cypher
CREATE FUNCTION ... AS { }User-defined functions with typed parameters
CREATE TRIGGER ... AS { }Event-driven logic on graph and document changes
CREATE POLICY ... USING ()Row-level security predicates
SYNC LABEL ... TO COLLECTIONBidirectional graph-document synchronization
EXPLAIN / PROFILEQuery plan analysis and profiling

Comments

Anvil supports several comment styles in Cypher queries. All comment markers are ignored inside quoted strings.

// C-style line comment
-- SQL-style line comment (note: --> is a relationship pattern, not a comment)
# Shell-style line comment

/* Block comment spanning
   multiple lines */

MATCH (n) // inline comment after a clause
RETURN n.name -- also works here