Skip to content

Commit

Permalink
cargo fmt fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
poster515 committed Jan 30, 2024
1 parent 5d900ed commit f8b2e53
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
8 changes: 6 additions & 2 deletions examples/measurement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ async fn main() -> Result<(), Box<dyn Error>> {
}

for m in measurements.iter() {
let tag_values = client.list_measurement_tag_values(bucket, &m, "host", Some(365)).await;
let tag_values = client
.list_measurement_tag_values(bucket, &m, "host", Some(365))
.await;
println!(
"tag values for measurement {} and tag {}: {:?}",
&m, "host", tag_values
);
}

for m in measurements.iter() {
let tag_values = client.list_measurement_tag_keys(bucket, &m, Some(365)).await;
let tag_values = client
.list_measurement_tag_keys(bucket, &m, Some(365))
.await;
println!(
"tag values for measurement {} and tag {}: {:?}",
&m, "host", tag_values
Expand Down
58 changes: 37 additions & 21 deletions src/api/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,21 @@ impl Client {

/// Returns bucket measurements
pub async fn list_measurements(
&self,
&self,
bucket: &str,
days_ago: Option<i64>
days_ago: Option<i64>,
) -> Result<Vec<String>, RequestError> {
let query = Query::new(format!(
r#"import "influxdata/influxdb/schema"
schema.measurements(bucket: "{bucket}"{}) "#,
schema.measurements(bucket: "{bucket}"{}) "#,
match days_ago {
Some(days_ago) => { format!(", start: -{}d", days_ago) },
None => { String::from("") }
Some(days_ago) => {
format!(", start: -{}d", days_ago)
}
None => {
String::from("")
}
}
));
self.exec_schema_query(query).await
Expand All @@ -273,7 +277,7 @@ schema.measurements(bucket: "{bucket}"{}) "#,
&self,
bucket: &str,
measurement: &str,
days_ago: Option<i64>
days_ago: Option<i64>,
) -> Result<Vec<String>, RequestError> {
let query = Query::new(format!(
r#"import "influxdata/influxdb/schema"
Expand All @@ -282,9 +286,14 @@ schema.measurements(bucket: "{bucket}"{}) "#,
bucket: "{bucket}",
measurement: "{measurement}",
{}
)"#, match days_ago {
Some(days_ago) => { format!("start: -{}d", days_ago) },
None => { String::from("") }
)"#,
match days_ago {
Some(days_ago) => {
format!("start: -{}d", days_ago)
}
None => {
String::from("")
}
}
));
self.exec_schema_query(query).await
Expand All @@ -296,7 +305,7 @@ schema.measurements(bucket: "{bucket}"{}) "#,
bucket: &str,
measurement: &str,
tag: &str,
days_ago: Option<i64>
days_ago: Option<i64>,
) -> Result<Vec<String>, RequestError> {
let query = Query::new(format!(
r#"import "influxdata/influxdb/schema"
Expand All @@ -306,9 +315,14 @@ schema.measurements(bucket: "{bucket}"{}) "#,
measurement: "{measurement}",
tag: "{tag}",
{}
)"#, match days_ago {
Some(days_ago) => { format!("start: -{}d", days_ago) },
None => { String::from("") }
)"#,
match days_ago {
Some(days_ago) => {
format!("start: -{}d", days_ago)
}
None => {
String::from("")
}
}
));
self.exec_schema_query(query).await
Expand All @@ -319,7 +333,7 @@ schema.measurements(bucket: "{bucket}"{}) "#,
&self,
bucket: &str,
measurement: &str,
days_ago: Option<i64>
days_ago: Option<i64>,
) -> Result<Vec<String>, RequestError> {
let query = Query::new(format!(
r#"import "influxdata/influxdb/schema"
Expand All @@ -328,18 +342,20 @@ schema.measurements(bucket: "{bucket}"{}) "#,
bucket: "{bucket}",
measurement: "{measurement}",
{}
)"#, match days_ago {
Some(days_ago) => { format!("start: -{}d", days_ago) },
None => { String::from("") }
)"#,
match days_ago {
Some(days_ago) => {
format!("start: -{}d", days_ago)
}
None => {
String::from("")
}
}
));
self.exec_schema_query(query).await
}

async fn exec_schema_query(
&self,
query: Query
) -> Result<Vec<String>, RequestError> {
async fn exec_schema_query(&self, query: Query) -> Result<Vec<String>, RequestError> {
let req_url = self.url("/api/v2/query");
let body = serde_json::to_string(&query).context(Serializing)?;

Expand Down

0 comments on commit f8b2e53

Please sign in to comment.