pub struct Vertex<T> { /* private fields */ }Expand description
Represents vertex within graph. Used during process of vertex deserialization
Implementations§
Source§impl<T> Vertex<T>
impl<T> Vertex<T>
pub fn id(&self) -> u64
Sourcepub fn label(&self) -> String
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}Sourcepub fn properties(&self) -> &T
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
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<'de, T> Deserialize<'de> for Vertex<T>where
T: Deserialize<'de>,
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>,
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>,
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>>
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 moreSource§fn accepts(ty: &Type) -> bool
fn accepts(ty: &Type) -> bool
Determines if a value of this type can be created from the specified
Postgres
Type.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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more