Expand description
petgraph-decypher – build petgraph graphs from OpenCypher queries.
§Overview
This crate provides three main entry points:
parse_cypher– parse a Cypher query string into the internal query plan.build_graph_from_cypher– parse a Cypher query and materialise allCREATE/MERGEoperations into apetgraph::Graphwith the defaultNodeData/EdgeDatatypes.build_graph_from_cypher_typed– generic version that accepts any types implementingCypherNodeandCypherEdge.
§Supported Cypher subset
| Feature | Status |
|---|---|
CREATE (n:Label {k: v})-[:TYPE]->(m) | ✅ materialised + executed |
MERGE (n:Label {k: v})-[:TYPE]->(m) | ✅ materialised + executed |
MATCH (n)-[r]->(m) WHERE n.p = v | ✅ evaluated |
RETURN n, n.prop AS alias / RETURN * | ✅ evaluated |
[DETACH] DELETE n | ✅ executed |
| Multiple clauses in one query | ✅ |
| Semicolon-separated statements | ✅ |
§Example
use petgraph_decypher::build_graph_from_cypher;
let graph = build_graph_from_cypher(
r#"CREATE (a:Person {name: "Alice"})-[:KNOWS]->(b:Person {name: "Bob"})"#,
)
.unwrap();
assert_eq!(graph.node_count(), 2);
assert_eq!(graph.edge_count(), 1);Re-exports§
pub use ast::BinaryOp;pub use ast::CaseExpr;pub use ast::Clause;pub use ast::CypherQuery;pub use ast::CypherValue;pub use ast::Expression;pub use ast::NodePattern;pub use ast::PathPattern;pub use ast::RelDirection;pub use ast::RelPattern;pub use ast::RelationshipLength;pub use ast::ReturnItem;pub use ast::SetItem;pub use ast::SortDirection;pub use ast::SortItem;pub use ast::UnaryOp;pub use ast::WhereExpr;pub use error::CypherError;pub use query::MatchStrategy;pub use query::Parameters;pub use query::PetgraphCypher;pub use query::QueryResult;pub use query::ResultValue;pub use query::Row;
Modules§
- ast
- Abstract Syntax Tree types for OpenCypher queries.
- error
- Error types for petgraph-decypher.
- query
- Query execution engine for running Cypher queries against a petgraph.
Structs§
- Edge
Data - Data stored at each edge in the graph built by
build_graph_from_cypher. - Node
Data - Data stored at each node in the graph built by
build_graph_from_cypher.
Traits§
- Cypher
Edge - Metadata required from edge weights during Cypher planning and execution.
- Cypher
Node - Metadata required from node weights during Cypher planning and execution.
- Cypher
Properties - Common property access used by the query planner and executor.
Functions§
- build_
graph_ from_ cypher - Parse a Cypher query and build a petgraph
Graphfrom itsCREATEandMERGEclauses. - build_
graph_ from_ cypher_ typed - Parse a Cypher query and build a petgraph
Graphfrom itsCREATEandMERGEclauses using custom node and edge types. - parse_
cypher - Parse a Cypher query string and return its HIR-backed query plan representation.