Struct cayley::path::Vertex
[-]
[+]
[src]
pub struct Vertex { // some fields omitted }
An interface to a Path with the ability to be executed as a Query to a database. The main entry point to ask for GraphNodes from database using Graph as an interceptor.
To query for anything you might describe with Path from database, use this pattern:
graph.find(Vertex::start(<NodeSelector>).<PathMethod>().<PathMethod>(<method_arg>).....<QueryMethod>())
.
Example:
use cayley::graph::Graph; use cayley::path::{Vertex, Path, Query}; // Query and Path trait imports are required use cayley::selector::{Tags, AnyNode, Predicate}; let graph = Graph::default().unwrap(); graph.find(Vertex::start(AnyNode) .As(Tags(vec!("tag-a", "tag-b"))) .OutP(Predicate("follows")) .All()).unwrap();
Another example:
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()) };
Sometimes it is wanted to separate a vertex instance from a query construction.
Use prepare
static method for this purpose, but then ensure to start a query with From
call:
#![allow(unused_result)] use cayley::Graph; use cayley::path::{Vertex, Path, Query}; use cayley::selector::{Node, Predicate}; let graph = Graph::default().unwrap(); let mut v = Vertex::prepare(); // NB: Do not finalize the queries you plan to reuse! v.From(Node("C")).OutP(Predicate("follows")); let mut other_v = Vertex::prepare(); other_v.From(Node("D")).Union(&v).All(); graph.find(&other_v).unwrap();
Methods
impl Vertex
fn start(nodes: NodeSelector) -> Vertex
Create a Vertex instance and start a query from NodeSelector
fn prepare() -> Vertex
Prepare a vertex instance to specify a query later. Ensure to start a query with .From()
method
if you use prepare()
.
fn From(&mut self, nodes: NodeSelector) -> &mut Vertex
A method for postponed query creation, intended to be used after the prepare()
method
on the same Vertex instance.