Struct cayley::graph::Graph [-]  [+] [src]

pub struct Graph {
    // some fields omitted
}

Provides access to currently running Cayley database, among with an ability to run queries there, and to write there your data (honestly, only if there's a graph.emit() method below—if not, it will just soon be there).

Methods

impl Graph

fn default() -> GraphResult<Graph>

Create a Graph which connects to the latest API at localhost:64210

fn new(host: &str, port: int, version: CayleyAPIVersion) -> GraphResult<Graph>

Create a Graph which connects to the host you specified manually

fn find(&self, query: &Query) -> GraphResult<GraphNodes>

Find nodes with the Query implementation (say, Vertex-path) and return them parsed

Since only Vertex implements Query trait following current spec, your code will look like that:

use cayley::graph::Graph;
use cayley::path::{Vertex, Path, Query};
use cayley::selector::{Predicate, Node};

let graph = Graph::default().unwrap();
graph.find(Vertex::start(Node("foo")).InP(Predicate("bar")).All()).unwrap();

fn exec(&self, query: String) -> GraphResult<GraphNodes>

Find nodes using raw pre-compiled query string and return them parsed

If you want to run just the pure stringified Gremlin queries, bypassing the string concatenation performed with path:: module members, this method is for you.

use cayley::Graph;
let graph = Graph::default().unwrap();
graph.exec("g.V(\"foo\").In(\"bar\").All()".to_string()).unwrap();

fn save(&self, reusable: &mut Reuse) -> GraphResult<()>

Save Morphism or any Reuse implementor in the database, equivalent to Gremin's var foo = g.Morphism()...

The difference is in the fact you set the name when you create a Morphism instance and then just pass it here, like:

use cayley::Graph;
use cayley::path::{Morphism, Path};
use cayley::selector::{Predicate, AnyTag};

let graph = Graph::default().unwrap();
let mut m = Morphism::start("foo");
m.Out(Predicate("follows"), AnyTag);
graph.save(&mut m).unwrap();

Currently no check is performed if Morphism was already saved or not to this graph, though it provides is_saved() method which may tell if this Morphism instance was saved at least once to some graph. If in future this check will be performed, this method definiton won't change, only there will be a new error type.

fn save_as(&self, name: &str, reusable: &mut Reuse) -> GraphResult<()>

Save Morphism or any Reuse implementor in the database, under the different name than the one used when it was created

use cayley::Graph;
use cayley::path::{Morphism, Path};
use cayley::selector::{Predicate, AnyTag};

let graph = Graph::default().unwrap();
let mut m = Morphism::start("foo");
m.Out(Predicate("follows"), AnyTag);
graph.save_as("bar", &mut m).unwrap();

Currently no check is performed if Morphism was already saved or not to this graph, though it provides is_saved() method which may tell if this Morphism instance was saved at least once to some graph. If in future this check will be performed, this method definiton won't change, only there will be a new error type.