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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use chrono::prelude::*;
use edn_derive::Serialize;
use transistor::client::Crux;
use transistor::types::http::{Actions, Order, TimeHistory};
use transistor::types::response::EntityHistoryResponse;
use transistor::types::CruxId;
async fn entity_history_timed() -> EntityHistoryResponse {
let person1 = Person {
crux__db___id: CruxId::new("jorge-3"),
first_name: "Michael".to_string(),
last_name: "Jorge".to_string(),
};
let person2 = Person {
crux__db___id: CruxId::new("manuel-1"),
first_name: "Diego".to_string(),
last_name: "Manuel".to_string(),
};
let client = Crux::new("localhost", "3000").http_client();
let timed = "2014-11-28T21:00:09-09:00"
.parse::<DateTime<FixedOffset>>()
.unwrap();
let start_timed = "2013-11-28T21:00:09-09:00"
.parse::<DateTime<Utc>>()
.unwrap();
let end_timed = "2015-11-28T21:00:09-09:00"
.parse::<DateTime<Utc>>()
.unwrap();
let time_history = TimeHistory::ValidTime(Some(start_timed), Some(end_timed));
let actions = Actions::new()
.append_put_timed(person1.clone(), timed)
.append_put_timed(person2, timed);
let _ = Crux::new("localhost", "3000")
.http_client()
.tx_log(actions)
.await
.unwrap();
let tx_body = client.entity_tx(person1.crux__db___id).await.unwrap();
let entity_history = client
.entity_history_timed(
tx_body.db___id.clone(),
Order::Asc,
true,
vec![time_history],
)
.await
.unwrap();
return entity_history;
}
#[tokio::main]
async fn main() {
let entity_history = entity_history_timed().await;
println!("{:#?}", entity_history);
// EntityHistoryResponse {
// history: [
// EntityHistoryElement {
// db___valid_time: 2014-11-28T12:00:09+00:00,
// tx___tx_id: 6,
// tx___tx_time: 2020-08-17T15:21:53.682+00:00,
// db___content_hash: "9d2c7102d6408d465f85b0b35dfb209b34daadd1",
// db__doc: Some(
// Map(
// Map(
// {
// ":crux.db/id": Key(
// ":jorge-3",
// ),
// ":first-name": Str(
// "Michael",
// ),
// ":last-name": Str(
// "Jorge",
// ),
// },
// ),
// ),
// ),
// },
// EntityHistoryElement {
// db___valid_time: 2014-11-29T06:00:09+00:00,
// tx___tx_id: 12,
// tx___tx_time: 2020-08-17T18:57:00.044+00:00,
// db___content_hash: "9d2c7102d6408d465f85b0b35dfb209b34daadd1",
// db__doc: Some(
// Map(
// Map(
// {
// ":crux.db/id": Key(
// ":jorge-3",
// ),
// ":first-name": Str(
// "Michael",
// ),
// ":last-name": Str(
// "Jorge",
// ),
// },
// ),
// ),
// ),
// },
// ],
// }
}
#[tokio::test]
async fn test_entity_history() {
let entity = entity_history_timed().await;
assert!(entity.history.len() > 0);
}
#[derive(Debug, Clone, Serialize)]
#[allow(non_snake_case)]
pub struct Person {
crux__db___id: CruxId,
first_name: String,
last_name: String,
}