fix influxdb derive macro
https://github.com/aprimadi/influxdb2/issues/17
This commit is contained in:
parent
dbd7860416
commit
5b48d471bb
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -6287,6 +6287,7 @@ dependencies = [
|
|||||||
"hdrhistogram",
|
"hdrhistogram",
|
||||||
"http",
|
"http",
|
||||||
"influxdb2",
|
"influxdb2",
|
||||||
|
"influxdb2-structmap",
|
||||||
"ipnet",
|
"ipnet",
|
||||||
"itertools",
|
"itertools",
|
||||||
"log",
|
"log",
|
||||||
|
@ -52,6 +52,7 @@ hashbrown = { version = "0.13.2", features = ["serde"] }
|
|||||||
hdrhistogram = "7.5.2"
|
hdrhistogram = "7.5.2"
|
||||||
http = "0.2.9"
|
http = "0.2.9"
|
||||||
influxdb2 = { version = "0.3", features = ["rustls"] }
|
influxdb2 = { version = "0.3", features = ["rustls"] }
|
||||||
|
influxdb2-structmap = "0.2.0"
|
||||||
ipnet = "2.7.1"
|
ipnet = "2.7.1"
|
||||||
itertools = "0.10.5"
|
itertools = "0.10.5"
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
|
@ -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<FixedOffset>,
|
|
||||||
}
|
|
||||||
|
|
||||||
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<dyn std::error::Error>> {
|
|
||||||
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<StockPrice> = client.query::<StockPrice>(Some(query)).await?;
|
|
||||||
println!("{:?}", res);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user