Crate cayley [stability]
[-]
[+]
[src]
Google Cayley Database Driver
Jump to: Graph | Vertex | Morphism.
Connection
To connect to a graph, start Cayley itself:
$ ./cayley http --dbpath=<your-database>
Then, bind driver to your host this way:
use cayley::{Graph, DefaultVersion}; let graph = match Graph::new("localhost", 64210, DefaultVersion) { Err(error) => fail!(error), Ok(graph) => graph };
For the moment, this code performs no connection at all, when you only create a Graph. On the other hand, the connection is established for every query. So this error, if happened, is not telling that connection was failed here, it just tells about malformed URL. But things may change, and even when they'll do, you still have a chance to pattern-match the error, if you need.
Query
Query pattern looks like this:
use cayley::{Graph, DefaultVersion}; use cayley::GraphNodes; use cayley::path::{Vertex, Query}; // Query trait import is required use cayley::selector::AnyNode; let graph = Graph::new("localhost", 64210, DefaultVersion).unwrap(); match graph.find(Vertex::start(AnyNode).All()) { Ok(GraphNodes(nodes)) => assert!(nodes.len() > 0), Err(error) => fail!(error.to_string()), };
So in general it looks like graph.find(<Query>)
.
GraphNodes is a wrapper for Vec<GraphNode>
.
GraphNode is a wrapper for HashMap<String, String>
Morphism used this way:
#![allow(unused_result)] use cayley::{Graph, DefaultVersion}; use cayley::path::Vertex as V; use cayley::path::Morphism as M; use cayley::path::{Path, Query}; // both traits imports are required use cayley::selector::{Predicate, Node}; let graph = Graph::new("localhost", 64210, DefaultVersion).unwrap(); let mut follows_m = M::start("foo"); follows_m.OutP(Predicate("follows")); graph.save(&mut follows_m).unwrap(); graph.find(V::start(Node("C")) .Follow(&follows_m) .Has(Predicate("status"), Node("cool_person")) .All()).unwrap();
API
Gremlin API is implemented through these entry points:
- Graph provides
.find(<Query>)
and.save(<Morphism>)
; - Vertex provides:
- Morphism provides:
- Path implemetation with
.Out(...)
,.In(...)
,.Has(...)
,.Or(...)
,.Follow(...)
, ...
- Path implemetation with
Follow the links above for a complete lists of methods and to get more information about every mentioned structure.
Reexports
pub use graph::{Graph, GraphNodes, GraphNode}; |
pub use graph::{V1, DefaultVersion}; |
Modules
errors | |
graph | |
path | |
selector |