6 releases (3 breaking)

0.4.1 Jan 24, 2023
0.4.0 Aug 8, 2021
0.3.1 Feb 28, 2021
0.2.0 Feb 22, 2021
0.1.0 Feb 21, 2021

#2499 in Database interfaces

MIT license

20KB
454 lines

influx_client

crates-badge docs-badge

A Rust library to interact with InfluxDB databases. It is still early in development, so expect bugs and missing features.

Things that work

  • Writing data to a bucket
  • Querying data in a certain time range (only relative so far)
  • Using filters in queries

Examples

Writing to a bucket:

use std::{collections::HashMap, time::SystemTime};

use influx_client::{
    Client, InfluxError, Precision, WriteQuery,
};

fn main() -> Result<(), InfluxError> {
    let client = Client::from_env("http://localhost:8086").expect("INFLUXDB_TOKEN not set");
    let mut tags = HashMap::new();
    tags.insert("t1", "v1");
    tags.insert("t2", "v2");
    let data = WriteQuery {
        name: "test",
        tags,
        field_name: "i",
        value: 42,
        timestamp: Some((SystemTime::now(), Precision::ns)),
    };

    client.insert("home", "home", Precision::ms, data)?;
}

Reading from a bucket:

use influx_client::{
    flux::functions::{NumericFilter, Range, StringFilter},
    Client, InfluxError, Precision, ReadQuery,
};

fn main() -> Result<(), InfluxError> {
    let client = Client::from_env("http://localhost:8086").expect("INFLUXDB_TOKEN not set");
    
    let q = ReadQuery::new("home")
        .range(Range::new(Some((-12, Precision::h)), None))
        .filter(StringFilter::Eq("_measurement", "test"))
        .filter(NumericFilter::Lt("_value", 99));

    println!("{}", client.get("home", q)?);
    Ok(())
}

Dependencies

~5–17MB
~224K SLoC