diff --git a/Cargo.lock b/Cargo.lock index 4365d4b6..d9635544 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -474,9 +474,10 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.35" +version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" +checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" + dependencies = [ "android-tzdata", "iana-time-zone", diff --git a/aw-client-rust/src/blocking.rs b/aw-client-rust/src/blocking.rs index f16dc1f0..7d6b6a97 100644 --- a/aw-client-rust/src/blocking.rs +++ b/aw-client-rust/src/blocking.rs @@ -64,7 +64,7 @@ impl AwClient { ); proxy_method!( query, - serde_json::Value, + Vec, query: &str, timeperiods: Vec<(DateTime, DateTime)> ); diff --git a/aw-client-rust/src/lib.rs b/aw-client-rust/src/lib.rs index dca5bb54..c95704a9 100644 --- a/aw-client-rust/src/lib.rs +++ b/aw-client-rust/src/lib.rs @@ -102,7 +102,7 @@ impl AwClient { &self, query: &str, timeperiods: Vec<(DateTime, DateTime)>, - ) -> Result { + ) -> Result, reqwest::Error> { let url = reqwest::Url::parse(format!("{}/api/0/query", self.baseurl).as_str()).unwrap(); // Format timeperiods as ISO8601 strings, separated by / @@ -111,11 +111,11 @@ impl AwClient { .map(|(start, stop)| (start.to_rfc3339(), stop.to_rfc3339())) .map(|(start, stop)| format!("{}/{}", start, stop)) .collect(); - + // Result is a sequence, one element per timeperiod self.client .post(url) .json(&json!({ - "query": query, + "query": query.split('\n').collect::>(), "timeperiods": timeperiods_str, })) .send() diff --git a/aw-client-rust/tests/test.rs b/aw-client-rust/tests/test.rs index 6f465f04..8803e41c 100644 --- a/aw-client-rust/tests/test.rs +++ b/aw-client-rust/tests/test.rs @@ -108,6 +108,22 @@ mod test { println!("Events: {events:?}"); assert!(events[0].duration == Duration::try_seconds(1).unwrap()); + // Query + let query = format!( + "events = query_bucket(\"{}\"); +RETURN = events;", + bucket.id + ); + let start: DateTime = DateTime::parse_from_rfc3339("1996-12-19T00:00:00-08:00") + .unwrap() + .into(); + let end: DateTime = DateTime::parse_from_rfc3339("2020-12-19T00:00:00-08:00") + .unwrap() + .into(); + let timeperiods = (start, end); + let query_result = client.query(&query, vec![timeperiods]).unwrap(); + println!("Query result: {query_result:?}"); + client .delete_event(&bucketname, events[0].id.unwrap()) .unwrap();