Crates.io | wasccgraph-actor |
lib.rs | wasccgraph-actor |
version | 0.0.2 |
source | src |
created_at | 2020-05-15 12:49:43.204564 |
updated_at | 2020-05-18 17:37:42.907264 |
description | waSCC Actor Support for graph database capability providers |
homepage | https://wascc.dev |
repository | https://github.com/wascc/redisgraph |
max_upload_size | |
id | 241843 |
size | 18,794 |
This crate provides waSCC actors with an API they can use to interact with a graph database. The exact implementation of the graph database (Neo4j, RedisGraph, etc) is immaterial to the actor developer using this API.
The following illustrates an example of consuming the graph guest API:
// Execute a Cypher query to add data
fn create_data() -> HandlerResult<codec::http::Response> {
info!("Creating graph data");
graph::default().graph("MotoGP").mutate("CREATE (:Rider {name: 'Valentino Rossi', birth_year: 1979})-[:rides]->(:Team {name: 'Yamaha'}), \
(:Rider {name:'Dani Pedrosa', birth_year: 1985, height: 1.58})-[:rides]->(:Team {name: 'Honda'}), \
(:Rider {name:'Andrea Dovizioso', birth_year: 1986, height: 1.67})-[:rides]->(:Team {name: 'Ducati'})")?;
Ok(codec::http::Response::ok())
}
// Execute a Cypher query to return data values
fn query_data() -> HandlerResult<codec::http::Response> {
info!("Querying graph data");
let (name, birth_year): (String, u32) = graph::default().graph("MotoGP").query(
"MATCH (r:Rider)-[:rides]->(t:Team) WHERE t.name = 'Yamaha' RETURN r.name, r.birth_year",
)?;
let result = json!({
"name": name,
"birth_year": birth_year
});
Ok(codec::http::Response::json(result, 200, "OK"))
}