AgeClient

Trait AgeClient 

Source
pub trait AgeClient {
    // Required methods
    fn connect_age<T>(params: &str, tls_mode: T) -> Result<Client, Error>
       where T: MakeTlsConnect<Socket> + 'static + Send,
             T::TlsConnect: Send,
             T::Stream: Send,
             <T::TlsConnect as TlsConnect<Socket>>::Future: Send;
    fn constraint(
        &mut self,
        graph: &str,
        label: &str,
        name: &str,
        constraint_text: &str,
    ) -> Result<u64, Error>;
    fn unique_index(
        &mut self,
        graph: &str,
        label: &str,
        name: &str,
        field: &str,
    ) -> Result<u64, Error>;
    fn required_constraint(
        &mut self,
        graph: &str,
        label: &str,
        name: &str,
        field: &str,
    ) -> Result<u64, Error>;
    fn create_graph(&mut self, name: &str) -> Result<u64, Error>;
    fn drop_graph(&mut self, name: &str) -> Result<u64, Error>;
    fn graph_exists(&mut self, name: &str) -> Result<bool, Error>;
    fn execute_cypher<T>(
        &mut self,
        graph: &str,
        cypher: &str,
        agtype: Option<AgType<T>>,
    ) -> Result<u64, Error>
       where T: Serialize + Debug + Sync;
    fn query_cypher<T>(
        &mut self,
        graph: &str,
        cypher: &str,
        agtype: Option<AgType<T>>,
    ) -> Result<Vec<Row>, Error>
       where T: Serialize + Debug + Sync;
    fn prepare_cypher(
        &mut self,
        graph: &str,
        cypher: &str,
        use_arg: bool,
    ) -> Result<Statement, Error>;
}
Expand description

Handles connecting, configuring and querying graph dbs within postgres instance

Required Methods§

Source

fn connect_age<T>(params: &str, tls_mode: T) -> Result<Client, Error>
where T: MakeTlsConnect<Socket> + 'static + Send, T::TlsConnect: Send, T::Stream: Send, <T::TlsConnect as TlsConnect<Socket>>::Future: Send,

Source

fn constraint( &mut self, graph: &str, label: &str, name: &str, constraint_text: &str, ) -> Result<u64, Error>

Create a new constraint for the certain label within graph

IMPORTANT: At least one object has to be created with a certain label

Source

fn unique_index( &mut self, graph: &str, label: &str, name: &str, field: &str, ) -> Result<u64, Error>

Create unique index for the certain field for the label within graph

IMPORTANT: At least one object has to be created with a certain label

Source

fn required_constraint( &mut self, graph: &str, label: &str, name: &str, field: &str, ) -> Result<u64, Error>

Source

fn create_graph(&mut self, name: &str) -> Result<u64, Error>

Source

fn drop_graph(&mut self, name: &str) -> Result<u64, Error>

Source

fn graph_exists(&mut self, name: &str) -> Result<bool, Error>

Source

fn execute_cypher<T>( &mut self, graph: &str, cypher: &str, agtype: Option<AgType<T>>, ) -> Result<u64, Error>
where T: Serialize + Debug + Sync,

Exexute cypher query, without any rows to be retured

Source

fn query_cypher<T>( &mut self, graph: &str, cypher: &str, agtype: Option<AgType<T>>, ) -> Result<Vec<Row>, Error>
where T: Serialize + Debug + Sync,

Query cypher for a single agtype (in a format of json)

IMPORTANT: You need to return result of the query as a map

Example:

MATCH (n: Person) WHERE n.name = 'Alfred' RETURN {name: n.name, surname: n.surname}
Source

fn prepare_cypher( &mut self, graph: &str, cypher: &str, use_arg: bool, ) -> Result<Statement, Error>

Prepare cypher query for future use

use apache_age::sync::{AgeClient, Client};
use apache_age::{AgType, NoTls, Vertex};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
struct Day<'a> {
    pub name: &'a str,
    pub is_rainy: bool,
    pub month: u8,
}

unsafe impl<'a> Sync for Day<'a> {}

pub fn main() {
    let mut client = Client::connect_age(
        "host=localhost user=postgres password=passwd port=8081",
        NoTls,
    )
    .unwrap();

    client.create_graph("prepared_statementes_sync").unwrap();

    let statement = client
        .prepare_cypher(
            "prepared_statementes_sync",
            "CREATE (x: PreparedDay { name: $name, is_rainy: $is_rainy, month: $month })",
            true,
        )
        .unwrap();

    let day = Day {
        name: "Some day",
        is_rainy: false,
        month: 2,
    };

    client.query(&statement, &[&AgType(day)]).unwrap();

    let x = client
        .query_cypher::<()>(
            "prepared_statementes_sync",
            "MATCH (x: PreparedDay) RETURN x",
            None,
        )
        .unwrap();

    let day: Vertex<Day> = x[0].get(0);
    assert_eq!(day.properties().month, 2);
    assert!(!day.properties().is_rainy);
    assert_eq!(day.properties().name, "Some day");

    client.drop_graph("prepared_statementes_sync").unwrap();
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§