GQB (Graph Query Builder)
GQB is part of the GQLite project project, it an API for building OpenCypher query with a high-level interface. It supports for creating graphs and querying existing graphs.
Usage
To use GQB in a project, add it to your Cargo.toml using:
Create Graph
use ;
let mut builder = default;
// Create a single node with label "a"
let n1 = builder.create_node;
// Create two nodes with respective label "b" and "c". The first node has
// a propery "name" with value "b label".
let = builder.create_nodes;
// Create an edge between `n1` and `n2`.
let _ = builder.create_edge;
// Create an edge between `n1` and `n3`, `n2` and `n3`, the second edge has
// a property "key" with value "b -> c".
let = builder.create_edges;
// Generate OpenCypher query and bindings.
let = builder.into_oc_query.unwrap;
// Execute the query in a GQLite database.
let connection = builder.create.unwrap;
let _ = connection.execute_oc_query.unwrap;
Match a Graph
use ;
let mut builder = default;
// Match for a node with label "a" and a property "id" with value `3`.
// The node can have other properties.
let n1 = builder.match_node;
// Create an anonymous variable for a node, aka, it will match any node.
let n2 = builder.node_variable;
// Match edges between any node that matches n1 and n2, and has label "b"
// and a property "id" with value `2`. The edge can have other properties.
let e1 = builder.match_edge;
// Return in the result, variable n1, e1 and n2.
builder.return_variable;
builder.return_variable;
builder.return_variable;
// Generate OpenCypher query and bindings.
let = builder.into_oc_query.unwrap;
// Execute the query in a GQLite database.
let connection = builder.create.unwrap;
let _ = connection.execute_oc_query.unwrap;