From 417df990161816a67e3880bdab782796e837c4f7 Mon Sep 17 00:00:00 2001 From: Sammy Harris Date: Thu, 18 Jan 2024 19:02:11 -0500 Subject: [PATCH] feat: added retention policy for v2 api --- influxdb/src/client/mod.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/influxdb/src/client/mod.rs b/influxdb/src/client/mod.rs index ad198bc..7d0ead1 100644 --- a/influxdb/src/client/mod.rs +++ b/influxdb/src/client/mod.rs @@ -141,6 +141,23 @@ impl Client { self } + /// Add a retention policy to [`Client`](crate::Client) + /// + /// This is designed for InfluxDB 2.x's backward-compatible API, which + /// maps databases and retention policies to buckets using the **database + /// and retention policy (DBRP) mapping service**. + /// See [InfluxDB Docs](https://docs.influxdata.com/influxdb/v2/reference/api/influxdb-1x/dbrp/) for more details. + #[must_use = "Creating a client is pointless unless you use it"] + pub fn with_retention_policy(mut self, retention_policy: S) -> Self + where + S: Into, + { + let mut with_retention_policy = self.parameters.as_ref().clone(); + with_retention_policy.insert("rp", retention_policy.into()); + self.parameters = Arc::new(with_retention_policy); + self + } + /// Returns the name of the database the client is using pub fn database_name(&self) -> &str { // safe to unwrap: we always set the database name in `Self::new`