1
2
3
4
5
6
7
8
9
10
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
use apache_age::sync::{AgeClient, Client};
use apache_age::{AgType, NoTls, Vertex};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
struct Day<'a> {
    pub name: &'a str,
    pub is_rainy: bool,
    pub month: u8,
}

unsafe impl<'a> Sync for Day<'a> {}

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();
}