Vertex

Struct 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)
11pub fn main() {
12    // Create client
13    let mut client = Client::connect_age(
14        "host=localhost user=postgres password=passwd port=8081",
15        NoTls,
16    )
17    .unwrap();
18
19    // Create graph
20    client.create_graph("my_apache_graph").unwrap();
21    assert!(client.graph_exists("my_apache_graph").unwrap());
22
23    // Using a simple postgres query to manipulate graph
24    client
25        .simple_query(
26            &("SELECT * FROM cypher('".to_string()
27                + "my_apache_graph"
28                + "', $$ "
29                + "CREATE(n:Person {name: 'T', surname: 'Doe'}) "
30                + "RETURN n "
31                + "$$) AS (v agtype)"),
32        )
33        .unwrap();
34
35    // Using a normal postgres query to operate on graph
36    match client.query(
37        &("SELECT v FROM ag_catalog.cypher('".to_string()
38            + "my_apache_graph"
39            + "', $$ "
40            + "MATCH(n: Person) WHERE n.name='T' "
41            + "RETURN n "
42            + "$$) AS (v ag_catalog.agtype)"),
43        &[],
44    ) {
45        Err(_e) => {}
46        Ok(query) => {
47            for row in query {
48                // Vertex usage
49                let person_vertex: Vertex<Person> = row.get(0);
50                assert_eq!(person_vertex.label(), "Person");
51                assert_eq!(person_vertex.properties().surname, "Doe");
52            }
53        }
54    }
55
56    // Using execute_cypher with some input variables
57    assert!(client
58        .execute_cypher(
59            "my_apache_graph",
60            "CREATE(n: Person {name: $name, surname: $surname})",
61            Some(AgType::<Person>(Person {
62                name: "John".into(),
63                surname: "Doe".into(),
64            })),
65        )
66        .is_ok());
67
68    // Using execute_cypher without some input variables
69    assert!(client
70        .execute_cypher::<()>(
71            "my_apache_graph",
72            "CREATE(n: Person {name: 'Ask', surname: 'Me'})",
73            None,
74        )
75        .is_ok());
76
77    // Using query_cypher without parameters
78    let rows = client
79        .query_cypher::<()>(
80            "my_apache_graph",
81            "
82            MATCH (n: Person) 
83            WHERE n.name = 'Ask' 
84            RETURN {name: n.name, surname: n.surname}
85        ",
86            None,
87        )
88        .unwrap();
89
90    let x: AgType<Person> = rows[0].get(0);
91    assert_eq!(x.0.surname, "Me");
92
93    // Prepared statements
94    let statement = client
95        .prepare_cypher(
96            "my_apache_graph",
97            "MATCH (n: Person) WHERE n.name = 'John' RETURN n",
98            false,
99        )
100        .unwrap();
101
102    let x = client.query(&statement, &[]).unwrap();
103    let john_doe: Vertex<Person> = x[0].get(0);
104    assert_eq!(john_doe.properties().surname, "Doe");
105
106    // Constraints
107    client
108        .required_constraint("my_apache_graph", "Person", "myconstraint", "surname")
109        .unwrap();
110
111    client
112        .unique_index("my_apache_graph", "Person", "myuniq", "name")
113        .unwrap();
114
115    assert!(client
116        .execute_cypher::<()>(
117            "my_apache_graph",
118            "CREATE (p: Person { name: 'No surname' })",
119            None
120        )
121        .is_err());
122
123    assert!(client
124        .execute_cypher::<()>(
125            "my_apache_graph",
126            "CREATE (p: Person { name: 'John', surname: 'Repeated name' })",
127            None
128        )
129        .is_err());
130
131    // Drop / destroy graph
132    client.drop_graph("my_apache_graph").unwrap();
133}
Source

pub fn properties(&self) -> &T

Examples found in repository?
examples/prepared_statements.rs (line 48)
14pub fn main() {
15    let mut client = Client::connect_age(
16        "host=localhost user=postgres password=passwd port=8081",
17        NoTls,
18    )
19    .unwrap();
20
21    client.create_graph("prepared_statementes_sync").unwrap();
22
23    let statement = client
24        .prepare_cypher(
25            "prepared_statementes_sync",
26            "CREATE (x: PreparedDay { name: $name, is_rainy: $is_rainy, month: $month })",
27            true,
28        )
29        .unwrap();
30
31    let day = Day {
32        name: "Some day",
33        is_rainy: false,
34        month: 2,
35    };
36
37    client.query(&statement, &[&AgType(day)]).unwrap();
38
39    let x = client
40        .query_cypher::<()>(
41            "prepared_statementes_sync",
42            "MATCH (x: PreparedDay) RETURN x",
43            None,
44        )
45        .unwrap();
46
47    let day: Vertex<Day> = x[0].get(0);
48    assert_eq!(day.properties().month, 2);
49    assert!(!day.properties().is_rainy);
50    assert_eq!(day.properties().name, "Some day");
51
52    client.drop_graph("prepared_statementes_sync").unwrap();
53}
More examples
Hide additional examples
examples/prepared_statements_async.rs (line 52)
15pub async fn main() {
16    let (client, _) = Client::connect_age(
17        "host=localhost user=postgres password=passwd port=8081",
18        NoTls,
19    )
20    .await
21    .unwrap();
22
23    client.create_graph("prepared_statements").await.unwrap();
24
25    let statement = client
26        .prepare_cypher(
27            "prepared_statements",
28            "CREATE (x: PreparedDay { name: $name, is_rainy: $is_rainy, month: $month })",
29            true,
30        )
31        .await
32        .unwrap();
33
34    let day = Day {
35        name: "Some day",
36        is_rainy: false,
37        month: 2,
38    };
39
40    client.query(&statement, &[&AgType(day)]).await.unwrap();
41
42    let x = client
43        .query_cypher::<()>(
44            "prepared_statements",
45            "MATCH (x: PreparedDay) RETURN x",
46            None,
47        )
48        .await
49        .unwrap();
50
51    let day: Vertex<Day> = x[0].get(0);
52    assert_eq!(day.properties().month, 2);
53    assert!(!day.properties().is_rainy);
54    assert_eq!(day.properties().name, "Some day");
55
56    client.drop_graph("prepared_statements").await.unwrap();
57}
examples/all.rs (line 51)
11pub fn main() {
12    // Create client
13    let mut client = Client::connect_age(
14        "host=localhost user=postgres password=passwd port=8081",
15        NoTls,
16    )
17    .unwrap();
18
19    // Create graph
20    client.create_graph("my_apache_graph").unwrap();
21    assert!(client.graph_exists("my_apache_graph").unwrap());
22
23    // Using a simple postgres query to manipulate graph
24    client
25        .simple_query(
26            &("SELECT * FROM cypher('".to_string()
27                + "my_apache_graph"
28                + "', $$ "
29                + "CREATE(n:Person {name: 'T', surname: 'Doe'}) "
30                + "RETURN n "
31                + "$$) AS (v agtype)"),
32        )
33        .unwrap();
34
35    // Using a normal postgres query to operate on graph
36    match client.query(
37        &("SELECT v FROM ag_catalog.cypher('".to_string()
38            + "my_apache_graph"
39            + "', $$ "
40            + "MATCH(n: Person) WHERE n.name='T' "
41            + "RETURN n "
42            + "$$) AS (v ag_catalog.agtype)"),
43        &[],
44    ) {
45        Err(_e) => {}
46        Ok(query) => {
47            for row in query {
48                // Vertex usage
49                let person_vertex: Vertex<Person> = row.get(0);
50                assert_eq!(person_vertex.label(), "Person");
51                assert_eq!(person_vertex.properties().surname, "Doe");
52            }
53        }
54    }
55
56    // Using execute_cypher with some input variables
57    assert!(client
58        .execute_cypher(
59            "my_apache_graph",
60            "CREATE(n: Person {name: $name, surname: $surname})",
61            Some(AgType::<Person>(Person {
62                name: "John".into(),
63                surname: "Doe".into(),
64            })),
65        )
66        .is_ok());
67
68    // Using execute_cypher without some input variables
69    assert!(client
70        .execute_cypher::<()>(
71            "my_apache_graph",
72            "CREATE(n: Person {name: 'Ask', surname: 'Me'})",
73            None,
74        )
75        .is_ok());
76
77    // Using query_cypher without parameters
78    let rows = client
79        .query_cypher::<()>(
80            "my_apache_graph",
81            "
82            MATCH (n: Person) 
83            WHERE n.name = 'Ask' 
84            RETURN {name: n.name, surname: n.surname}
85        ",
86            None,
87        )
88        .unwrap();
89
90    let x: AgType<Person> = rows[0].get(0);
91    assert_eq!(x.0.surname, "Me");
92
93    // Prepared statements
94    let statement = client
95        .prepare_cypher(
96            "my_apache_graph",
97            "MATCH (n: Person) WHERE n.name = 'John' RETURN n",
98            false,
99        )
100        .unwrap();
101
102    let x = client.query(&statement, &[]).unwrap();
103    let john_doe: Vertex<Person> = x[0].get(0);
104    assert_eq!(john_doe.properties().surname, "Doe");
105
106    // Constraints
107    client
108        .required_constraint("my_apache_graph", "Person", "myconstraint", "surname")
109        .unwrap();
110
111    client
112        .unique_index("my_apache_graph", "Person", "myuniq", "name")
113        .unwrap();
114
115    assert!(client
116        .execute_cypher::<()>(
117            "my_apache_graph",
118            "CREATE (p: Person { name: 'No surname' })",
119            None
120        )
121        .is_err());
122
123    assert!(client
124        .execute_cypher::<()>(
125            "my_apache_graph",
126            "CREATE (p: Person { name: 'John', surname: 'Repeated name' })",
127            None
128        )
129        .is_err());
130
131    // Drop / destroy graph
132    client.drop_graph("my_apache_graph").unwrap();
133}

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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>,