Getting Started with Rust
CypherLite is a native Rust library. Add it to your project with Cargo and start working with graph data in minutes.
Installation
Add the dependency
Add cypherlite-query to your Cargo.toml:
[dependencies]
cypherlite-query = "1.2"To enable optional features:
[dependencies]
cypherlite-query = { version = "1.2", features = ["temporal-edge", "plugin"] }Available Feature Flags
| Flag | Description |
|---|---|
temporal-core | Temporal graph support (enabled by default) |
temporal-edge | Temporal edge attributes |
subgraph | Subgraph extraction |
hypergraph | Hypergraph support (requires subgraph) |
full-temporal | All temporal features |
plugin | Plugin system |
Build your project
cargo buildBasic Usage
Open a Database
use cypherlite_query::CypherLite;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Open or create a database file
let db = CypherLite::open("my_graph.cyl")?;
// Use the database...
Ok(())
}CypherLite automatically creates the database file if it does not exist. The file uses the .cyl extension by convention.
Create Nodes and Relationships
// Create nodes with labels and properties
db.execute("CREATE (a:Person {name: 'Alice', age: 30})")?;
db.execute("CREATE (b:Person {name: 'Bob', age: 25})")?;
// Create a relationship between nodes
db.execute(
"MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'}) \
CREATE (a)-[:KNOWS {since: 2023}]->(b)"
)?;Query Data
let result = db.execute(
"MATCH (p:Person) WHERE p.age > 20 RETURN p.name, p.age ORDER BY p.age DESC"
)?;
for row in result {
let row = row?;
let name = row.get("p.name").unwrap();
let age = row.get("p.age").unwrap();
println!("{}: {}", name, age);
}Update Properties
db.execute(
"MATCH (p:Person {name: 'Alice'}) SET p.age = 31"
)?;Delete Nodes and Relationships
// Delete a relationship
db.execute(
"MATCH (a:Person {name: 'Alice'})-[r:KNOWS]->(b:Person {name: 'Bob'}) DELETE r"
)?;
// Delete a node (must have no relationships)
db.execute("MATCH (p:Person {name: 'Bob'}) DELETE p")?;Supported Cypher Operations
CypherLite supports an openCypher subset:
MATCH- Pattern matching for nodes and relationshipsCREATE- Create nodes and relationshipsMERGE- Create if not exists, match if existsSET- Update propertiesDELETE- Remove nodes and relationshipsRETURN- Specify output columnsWHERE- Filter conditionsWITH- Chain query partsORDER BY- Sort results
API Documentation
Full Rust API documentation is available on docs.rs.
Requirements
- Rust: 1.84+ (MSRV)
- Platform: Linux, macOS, Windows