prepared_statements_async/
prepared_statements_async.rs1use apache_age::tokio::{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
14#[tokio::main]
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}