From 5b48d471bb2b1fa674cb5a25405dad428288fe20 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Tue, 21 Feb 2023 21:24:04 -0800 Subject: [PATCH] fix influxdb derive macro https://github.com/aprimadi/influxdb2/issues/17 --- Cargo.lock | 1 + web3_proxy/Cargo.toml | 1 + web3_proxy/examples/influxdb2.rs | 42 -------------------------------- 3 files changed, 2 insertions(+), 42 deletions(-) delete mode 100644 web3_proxy/examples/influxdb2.rs diff --git a/Cargo.lock b/Cargo.lock index b26c57a7..b5495b8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6287,6 +6287,7 @@ dependencies = [ "hdrhistogram", "http", "influxdb2", + "influxdb2-structmap", "ipnet", "itertools", "log", diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index e1aaef47..f4aee03c 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -52,6 +52,7 @@ hashbrown = { version = "0.13.2", features = ["serde"] } hdrhistogram = "7.5.2" http = "0.2.9" influxdb2 = { version = "0.3", features = ["rustls"] } +influxdb2-structmap = "0.2.0" ipnet = "2.7.1" itertools = "0.10.5" log = "0.4.17" diff --git a/web3_proxy/examples/influxdb2.rs b/web3_proxy/examples/influxdb2.rs deleted file mode 100644 index b16793de..00000000 --- a/web3_proxy/examples/influxdb2.rs +++ /dev/null @@ -1,42 +0,0 @@ -use chrono::{DateTime, FixedOffset}; -use influxdb2::models::Query; -use influxdb2::{Client, FromDataPoint, FromMap}; - -#[derive(Debug, FromDataPoint)] -pub struct StockPrice { - ticker: String, - value: f64, - time: DateTime, -} - -impl Default for StockPrice { - fn default() -> Self { - Self { - ticker: "".to_string(), - value: 0_f64, - time: chrono::MIN_DATETIME.with_timezone(&chrono::FixedOffset::east(7 * 3600)), - } - } -} - -#[tokio::main] -async fn main() -> Result<(), Box> { - let host = std::env::var("INFLUXDB_HOST").unwrap(); - let org = std::env::var("INFLUXDB_ORG").unwrap(); - let token = std::env::var("INFLUXDB_TOKEN").unwrap(); - let client = Client::new(host, org, token); - - let qs = format!( - "from(bucket: \"stock-prices\") - |> range(start: -1w) - |> filter(fn: (r) => r.ticker == \"{}\") - |> last() - ", - "AAPL" - ); - let query = Query::new(qs.to_string()); - let res: Vec = client.query::(Some(query)).await?; - println!("{:?}", res); - - Ok(()) -}