aprimadi/influxdb2

failed to resolve: use of undeclared crate or module `influxdb2_structmap` use of undeclared crate or module `influxdb2_structmap`

BlinkyStitt opened this issue · 2 comments

I'm just trying to get the example in the readme to compile and got a compilation error.

use chrono::{DateTime, FixedOffset};
use influxdb2::models::Query;
use influxdb2::{Client, FromDataPoint};

#[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(())
}

cargo check says:

failed to resolve: use of undeclared crate or module `influxdb2_structmap`
use of undeclared crate or module `influxdb2_structmap`

use of deprecated constant `chrono::MIN_DATETIME`: Use DateTime::MIN_UTC instead
`#[warn(deprecated)]` on by default

vscode shows the error on the FromDataPoint in #[derive(Debug, FromDataPoint)]

What am I doing wrong?

I was able to fix this by adding influxdb2-structmap = "0.2.0" to my app's Cargo.toml. It felt weird to need it in my own repo when I'm using a macro from influxdb2 though. Especially since influxdb2-structmap is already listed as a dependency in influxdb2's Cargo.toml. Maybe there's just something I'm not understanding about macros though.

also, chrono::MIN_DATETIME and FixedOffset::east are deprecated now