diff --git a/docs/examples/py/src/data_management_delete_query.py b/docs/examples/py/src/data_management_delete_query.py index b023650a..b29c768e 100644 --- a/docs/examples/py/src/data_management_delete_query.py +++ b/docs/examples/py/src/data_management_delete_query.py @@ -26,7 +26,7 @@ async def main(): assert removed_records == 2 # You can also delete all records with a specific label - await bucket.remove_query("py-example", ts, ts + 2, where={"&key1": {"$eq": "value1"}}) + await bucket.remove_query("py-example", ts, ts + 2, when={"&key1": {"$eq": "value1"}}) # Or each N-th record await bucket.remove_query("py-example", ts, ts + 2, each_n=2) diff --git a/docs/examples/rs/Cargo.toml b/docs/examples/rs/Cargo.toml index 0d3ce21a..e6f95179 100644 --- a/docs/examples/rs/Cargo.toml +++ b/docs/examples/rs/Cargo.toml @@ -7,7 +7,8 @@ edition = "2021" [dependencies] reduct-rs= { git = "https://github.com/reductstore/reduct-rs.git"} +serde_json = "1.0.133" tokio = { version = "1", features = ["rt-multi-thread"]} bytes = "1.6.0" futures = "0.3.30" -futures-util = "0.3.30" \ No newline at end of file +futures-util = "0.3.30" diff --git a/docs/examples/rs/examples/data_management_delete_query.rs b/docs/examples/rs/examples/data_management_delete_query.rs index a7f5abae..c57a1752 100644 --- a/docs/examples/rs/examples/data_management_delete_query.rs +++ b/docs/examples/rs/examples/data_management_delete_query.rs @@ -2,6 +2,7 @@ use std::time::{Duration, SystemTime}; use bytes::Bytes; use reduct_rs::{ErrorCode, RecordBuilder, ReductClient, ReductError}; +use serde_json::json; use tokio; #[tokio::main] @@ -24,7 +25,7 @@ async fn main() -> Result<(), ReductError> { bucket .write_record("rs-example") - .timestamp(timestamp + Duration::from_secs(1)) + .timestamp(timestamp + Duration::from_secs(1)) .data(Bytes::from("Some more binary data")) .send() .await?; @@ -41,15 +42,11 @@ async fn main() -> Result<(), ReductError> { // You can also delete all records with a specific label bucket .remove_query("rs-example") - .add_include("label1", "value1") + .when(json!({"&key1": {"$eq": "value1"}})) .send() .await?; // Or each N-th record - bucket - .remove_query("rs-example") - .each_n(2) - .send() - .await?; + bucket.remove_query("rs-example").each_n(2).send().await?; Ok(()) } diff --git a/docs/examples/rs/examples/data_management_delete_records.rs b/docs/examples/rs/examples/data_management_delete_records.rs index 11aebba0..d08bec1e 100644 --- a/docs/examples/rs/examples/data_management_delete_records.rs +++ b/docs/examples/rs/examples/data_management_delete_records.rs @@ -24,7 +24,7 @@ async fn main() -> Result<(), ReductError> { bucket .write_record("rs-example") - .timestamp(timestamp + Duration::from_secs(1)) + .timestamp(timestamp + Duration::from_secs(1)) .data(Bytes::from("Some more binary data")) .send() .await?; @@ -39,8 +39,10 @@ async fn main() -> Result<(), ReductError> { // Delete a batch of records let batch = bucket.remove_batch("rs-example"); let errors = batch - .add_timestamp(timestamp) // was already deleted, so this error will be in the errors map - .add_timestamp(timestamp + Duration::from_secs(1)).send().await?; + .add_timestamp(timestamp) // was already deleted, so this error will be in the errors map + .add_timestamp(timestamp + Duration::from_secs(1)) + .send() + .await?; assert_eq!(errors.len(), 1); assert_eq!(errors.values().next().unwrap().status, ErrorCode::NotFound); diff --git a/docs/examples/rs/examples/data_management_update_labels.rs b/docs/examples/rs/examples/data_management_update_labels.rs index a81e77bc..67244243 100644 --- a/docs/examples/rs/examples/data_management_update_labels.rs +++ b/docs/examples/rs/examples/data_management_update_labels.rs @@ -26,7 +26,7 @@ async fn main() -> Result<(), ReductError> { bucket .write_record("rs-example") - .timestamp(timestamp + Duration::from_secs(1)) + .timestamp(timestamp + Duration::from_secs(1)) .add_label("key1", "value1") .add_label("key2", "value2") .data(Bytes::from("Some more binary data")) @@ -41,7 +41,11 @@ async fn main() -> Result<(), ReductError> { .update_label("key1", "value3") .send() .await?; - let record = bucket.read_record("rs-example").timestamp(timestamp).send().await?; + let record = bucket + .read_record("rs-example") + .timestamp(timestamp) + .send() + .await?; assert_eq!(record.labels().get("key1"), Some(&"value3".to_string())); assert_eq!(record.labels().get("key2"), None); @@ -49,16 +53,17 @@ async fn main() -> Result<(), ReductError> { let record1 = RecordBuilder::new() .timestamp(timestamp) .add_label("key1", "value1") - .add_label("key2", "") // Remove label "key2" + .add_label("key2", "") // Remove label "key2" .build(); let record2 = RecordBuilder::new() .timestamp(timestamp + Duration::from_secs(1)) .add_label("key1", "value1") - .add_label("key2", "") // Remove label "key2" + .add_label("key2", "") // Remove label "key2" .build(); - let errors = bucket.update_batch("rs-example") + let errors = bucket + .update_batch("rs-example") .add_records(vec![record1, record2]) .send() .await?; diff --git a/docs/examples/rs/examples/data_querying_filter.rs b/docs/examples/rs/examples/data_querying_filter.rs index 245eff32..ca2b2327 100644 --- a/docs/examples/rs/examples/data_querying_filter.rs +++ b/docs/examples/rs/examples/data_querying_filter.rs @@ -1,5 +1,6 @@ use futures::StreamExt; use reduct_rs::{ReductClient, ReductError}; +use serde_json::json; use tokio; #[tokio::main] @@ -18,8 +19,10 @@ async fn main() -> Result<(), ReductError> { // Query 10 photos from "imdb" entry which taken in 2006 but don't contain "Rowan Atkinson" let query = bucket .query("imdb") - .add_include("photo_taken", "2006") - .add_exclude("name", "b'Rowan Atkinson'") + .when(json!({ + "&photo_taken": {"$gt": 2006}, + "&name": {"$ne": "b'Rowan Atkinson'"}, + })) .limit(10) .send() .await?; diff --git a/docs/examples/rs/examples/quick_start.rs b/docs/examples/rs/examples/quick_start.rs index ba38fcc1..30ee8561 100644 --- a/docs/examples/rs/examples/quick_start.rs +++ b/docs/examples/rs/examples/quick_start.rs @@ -1,6 +1,6 @@ -use bytes::Bytes; use futures_util::stream::StreamExt; use reduct_rs::{QuotaType, ReductClient, ReductError}; +use serde_json::json; use std::pin::pin; use std::time::{Duration, SystemTime}; use tokio; @@ -22,27 +22,30 @@ async fn main() -> Result<(), ReductError> { .send() .await?; - // 3. Write some data with timestamps in the 'sensor-1' entry + // 3. Write some data with timestamps and labels to the 'entry-1' entry let start = SystemTime::now(); bucket .write_record("sensor-1") - .data("Record #1") + .data("") .timestamp(start) + .add_label("score", 10) .send() .await?; bucket .write_record("sensor-1") - .data("Record #2") + .data("") .timestamp(start + Duration::from_secs(1)) + .add_label("score", 20) .send() .await?; - // 4. Query the data by time range + // 4. Query the data by time range and condition let query = bucket .query("sensor-1") .start(start) .stop(start + Duration::from_secs(2)) + .when(json!({"&score": {"$gt": 15}})) .send() .await?;