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
| Clause | Description |
|---|---|
| MATCH | Pattern match against the graph |
| OPTIONAL MATCH | Match with null padding for missing patterns |
| WHERE | Filter matched results |
| RETURN | Project results with aliases |
| WITH | Chain query stages, project intermediate results |
| ORDER BY | Sort results (ASC / DESC) |
| SKIP / LIMIT | Paginate results |
| UNWIND | Expand a list into rows |
| CREATE | Create nodes and relationships |
| MERGE | Match or create a pattern |
| SET | Update properties or add labels |
| REMOVE | Remove properties or labels |
| DELETE / DETACH DELETE | Delete nodes and relationships |
| UNION / UNION ALL | Combine result sets |
| CALL ... YIELD | Invoke stored functions |
| FOREACH | Iterate 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.
| Extension | Description |
|---|---|
| CREATE / MATCH / UPSERT / DELETE DOCUMENT | Native 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 COLLECTION | Bidirectional graph-document synchronization |
| EXPLAIN / PROFILE | Query 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