Struct apache_age::Vertex

source ·
pub struct Vertex<T> { /* private fields */ }
Expand description

Represents vertex within graph. Used during process of vertex deserialization

Implementations§

source§

impl<T> Vertex<T>

source

pub fn id(&self) -> u64

source

pub fn label(&self) -> String

Examples found in repository?
examples/all.rs (line 50)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
pub fn main() {
    // Create client
    let mut client = Client::connect_age(
        "host=localhost user=postgres password=passwd port=8081",
        NoTls,
    )
    .unwrap();

    // Create graph
    client.create_graph("my_apache_graph").unwrap();
    assert!(client.graph_exists("my_apache_graph").unwrap());

    // Using a simple postgres query to manipulate graph
    client
        .simple_query(
            &("SELECT * FROM cypher('".to_string()
                + "my_apache_graph"
                + "', $$ "
                + "CREATE(n:Person {name: 'T', surname: 'Doe'}) "
                + "RETURN n "
                + "$$) AS (v agtype)"),
        )
        .unwrap();

    // Using a normal postgres query to operate on graph
    match client.query(
        &("SELECT v FROM ag_catalog.cypher('".to_string()
            + "my_apache_graph"
            + "', $$ "
            + "MATCH(n: Person) WHERE n.name='T' "
            + "RETURN n "
            + "$$) AS (v ag_catalog.agtype)"),
        &[],
    ) {
        Err(_e) => {}
        Ok(query) => {
            for row in query {
                // Vertex usage
                let person_vertex: Vertex<Person> = row.get(0);
                assert_eq!(person_vertex.label(), "Person");
                assert_eq!(person_vertex.properties().surname, "Doe");
            }
        }
    }

    // Using execute_cypher with some input variables
    assert!(client
        .execute_cypher(
            "my_apache_graph",
            "CREATE(n: Person {name: $name, surname: $surname})",
            Some(AgType::<Person>(Person {
                name: "John".into(),
                surname: "Doe".into(),
            })),
        )
        .is_ok());

    // Using execute_cypher without some input variables
    assert!(client
        .execute_cypher::<()>(
            "my_apache_graph",
            "CREATE(n: Person {name: 'Ask', surname: 'Me'})",
            None,
        )
        .is_ok());

    // Using query_cypher without parameters
    let rows = client
        .query_cypher::<()>(
            "my_apache_graph",
            "
            MATCH (n: Person) 
            WHERE n.name = 'Ask' 
            RETURN {name: n.name, surname: n.surname}
        ",
            None,
        )
        .unwrap();

    let x: AgType<Person> = rows[0].get(0);
    assert_eq!(x.0.surname, "Me");

    // Prepared statements
    let statement = client
        .prepare_cypher(
            "my_apache_graph",
            "MATCH (n: Person) WHERE n.name = 'John' RETURN n",
            false,
        )
        .unwrap();

    let x = client.query(&statement, &[]).unwrap();
    let john_doe: Vertex<Person> = x[0].get(0);
    assert_eq!(john_doe.properties().surname, "Doe");

    // Constraints
    client
        .required_constraint("my_apache_graph", "Person", "myconstraint", "surname")
        .unwrap();

    client
        .unique_index("my_apache_graph", "Person", "myuniq", "name")
        .unwrap();

    assert!(client
        .execute_cypher::<()>(
            "my_apache_graph",
            "CREATE (p: Person { name: 'No surname' })",
            None
        )
        .is_err());

    assert!(client
        .execute_cypher::<()>(
            "my_apache_graph",
            "CREATE (p: Person { name: 'John', surname: 'Repeated name' })",
            None
        )
        .is_err());

    // Drop / destroy graph
    client.drop_graph("my_apache_graph").unwrap();
}
source

pub fn properties(&self) -> &T

Examples found in repository?
examples/prepared_statements.rs (line 48)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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();
}
More examples
Hide additional examples
examples/prepared_statements_async.rs (line 52)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
pub async fn main() {
    let (client, _) = Client::connect_age(
        "host=localhost user=postgres password=passwd port=8081",
        NoTls,
    )
    .await
    .unwrap();

    client.create_graph("prepared_statements").await.unwrap();

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

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

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

    let x = client
        .query_cypher::<()>(
            "prepared_statements",
            "MATCH (x: PreparedDay) RETURN x",
            None,
        )
        .await
        .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_statements").await.unwrap();
}
examples/all.rs (line 51)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
pub fn main() {
    // Create client
    let mut client = Client::connect_age(
        "host=localhost user=postgres password=passwd port=8081",
        NoTls,
    )
    .unwrap();

    // Create graph
    client.create_graph("my_apache_graph").unwrap();
    assert!(client.graph_exists("my_apache_graph").unwrap());

    // Using a simple postgres query to manipulate graph
    client
        .simple_query(
            &("SELECT * FROM cypher('".to_string()
                + "my_apache_graph"
                + "', $$ "
                + "CREATE(n:Person {name: 'T', surname: 'Doe'}) "
                + "RETURN n "
                + "$$) AS (v agtype)"),
        )
        .unwrap();

    // Using a normal postgres query to operate on graph
    match client.query(
        &("SELECT v FROM ag_catalog.cypher('".to_string()
            + "my_apache_graph"
            + "', $$ "
            + "MATCH(n: Person) WHERE n.name='T' "
            + "RETURN n "
            + "$$) AS (v ag_catalog.agtype)"),
        &[],
    ) {
        Err(_e) => {}
        Ok(query) => {
            for row in query {
                // Vertex usage
                let person_vertex: Vertex<Person> = row.get(0);
                assert_eq!(person_vertex.label(), "Person");
                assert_eq!(person_vertex.properties().surname, "Doe");
            }
        }
    }

    // Using execute_cypher with some input variables
    assert!(client
        .execute_cypher(
            "my_apache_graph",
            "CREATE(n: Person {name: $name, surname: $surname})",
            Some(AgType::<Person>(Person {
                name: "John".into(),
                surname: "Doe".into(),
            })),
        )
        .is_ok());

    // Using execute_cypher without some input variables
    assert!(client
        .execute_cypher::<()>(
            "my_apache_graph",
            "CREATE(n: Person {name: 'Ask', surname: 'Me'})",
            None,
        )
        .is_ok());

    // Using query_cypher without parameters
    let rows = client
        .query_cypher::<()>(
            "my_apache_graph",
            "
            MATCH (n: Person) 
            WHERE n.name = 'Ask' 
            RETURN {name: n.name, surname: n.surname}
        ",
            None,
        )
        .unwrap();

    let x: AgType<Person> = rows[0].get(0);
    assert_eq!(x.0.surname, "Me");

    // Prepared statements
    let statement = client
        .prepare_cypher(
            "my_apache_graph",
            "MATCH (n: Person) WHERE n.name = 'John' RETURN n",
            false,
        )
        .unwrap();

    let x = client.query(&statement, &[]).unwrap();
    let john_doe: Vertex<Person> = x[0].get(0);
    assert_eq!(john_doe.properties().surname, "Doe");

    // Constraints
    client
        .required_constraint("my_apache_graph", "Person", "myconstraint", "surname")
        .unwrap();

    client
        .unique_index("my_apache_graph", "Person", "myuniq", "name")
        .unwrap();

    assert!(client
        .execute_cypher::<()>(
            "my_apache_graph",
            "CREATE (p: Person { name: 'No surname' })",
            None
        )
        .is_err());

    assert!(client
        .execute_cypher::<()>(
            "my_apache_graph",
            "CREATE (p: Person { name: 'John', surname: 'Repeated name' })",
            None
        )
        .is_err());

    // Drop / destroy graph
    client.drop_graph("my_apache_graph").unwrap();
}

Trait Implementations§

source§

impl<T: Debug> Debug for Vertex<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de, T> Deserialize<'de> for Vertex<T>
where T: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'a, T> FromSql<'a> for Vertex<T>
where T: Deserialize<'a>,

source§

fn from_sql( ty: &Type, raw: &'a [u8] ) -> Result<Vertex<T>, Box<dyn Error + Sync + Send>>

Creates a new value of this type from a buffer of data of the specified Postgres Type in its binary format. Read more
source§

fn accepts(ty: &Type) -> bool

Determines if a value of this type can be created from the specified Postgres Type.
source§

fn from_sql_null(ty: &Type) -> Result<Self, Box<dyn Error + Send + Sync>>

Creates a new value of this type from a NULL SQL value. Read more
source§

fn from_sql_nullable( ty: &Type, raw: Option<&'a [u8]> ) -> Result<Self, Box<dyn Error + Send + Sync>>

A convenience function that delegates to from_sql and from_sql_null depending on the value of raw.
source§

impl<T> Serialize for Vertex<T>
where T: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Vertex<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Vertex<T>
where T: RefUnwindSafe,

§

impl<T> Send for Vertex<T>
where T: Send,

§

impl<T> Sync for Vertex<T>
where T: Sync,

§

impl<T> Unpin for Vertex<T>
where T: Unpin,

§

impl<T> UnwindSafe for Vertex<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> FromSqlOwned for T
where T: for<'a> FromSql<'a>,