2个版本
0.0.2 | 2020年5月18日 |
---|---|
0.0.1 | 2020年5月15日 |
#1367 in WebAssembly
30KB
492 行
waSCC图Actor API
此crate为waSCC actors提供API,使它们能够与图数据库交互。使用此API的actor开发者对图数据库的特定实现(Neo4j、RedisGraph等)无关紧要。
以下示例展示了如何消费图客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"))
}
依赖项
~1.2–2MB
~44K SLoC