prepared_statements/
prepared_statements.rs1use apache_age::sync::{AgeClient, Client};
2use apache_age::{AgType, NoTls, Vertex};
3use serde::{Deserialize, Serialize};
4
5#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
6struct Day<'a> {
7 pub name: &'a str,
8 pub is_rainy: bool,
9 pub month: u8,
10}
11
12unsafe impl<'a> Sync for Day<'a> {}
13
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}