17 releases

0.7.2 Feb 14, 2024
0.7.1 Sep 8, 2023
0.7.0 Jul 3, 2023
0.6.0 Mar 4, 2023
0.0.3 Jul 14, 2019

#37 in Database interfaces

Download history 2038/week @ 2024-08-05 1588/week @ 2024-08-12 1609/week @ 2024-08-19 2080/week @ 2024-08-26 1739/week @ 2024-09-02 1983/week @ 2024-09-09 1669/week @ 2024-09-16 2283/week @ 2024-09-23 1802/week @ 2024-09-30 1540/week @ 2024-10-07 1976/week @ 2024-10-14 2122/week @ 2024-10-21 2237/week @ 2024-10-28 1864/week @ 2024-11-04 2118/week @ 2024-11-11 1984/week @ 2024-11-18

8,328 downloads per month
Used in 28 crates (21 directly)

MIT license

82KB
1.5K SLoC


rust-influxdb

Unofficial InfluxDB Driver for Rust

Build Status Coverage Report Documentation Status Build with Rust Minimum Rust Version: 1.65

This library is a work in progress. This means a feature you might need is not implemented yet or could be handled better.

Pull requests are always welcome. See Contributing and Code of Conduct. For a list of past changes, see CHANGELOG.md.

Currently Supported Features

  • Reading and Writing to InfluxDB
  • Optional Serde Support for Deserialization
  • Running multiple queries in one request (e.g. SELECT * FROM weather_berlin; SELECT * FROM weather_london)
  • Writing single or multiple measurements in one request (e.g. WriteQuery or Vec<WriteQuery> argument)
  • Authenticated and Unauthenticated Connections
  • async/await support
  • #[derive(InfluxDbWriteable)] Derive Macro for Writing / Reading into Structs
  • GROUP BY support
  • Tokio and async-std support (see example below) or available backends
  • Swappable HTTP backends (see below)

Quickstart

Add the following to your Cargo.toml

influxdb = { version = "0.7.2", features = ["derive"] }

For an example with using Serde deserialization, please refer to serde_integration

use chrono::{DateTime, Utc};
use influxdb::{Client, Error, InfluxDbWriteable, ReadQuery, Timestamp};

#[tokio::main]
// or #[async_std::main] if you prefer
async fn main() -> Result<(), Error> {
    // Connect to db `test` on `http://localhost:8086`
    let client = Client::new("http://localhost:8086", "test");

    #[derive(InfluxDbWriteable)]
    struct WeatherReading {
        time: DateTime<Utc>,
        humidity: i32,
        #[influxdb(tag)]
        wind_direction: String,
    }

    // Let's write some data into a measurement called `weather`
    let weather_readings = vec![
        WeatherReading {
            time: Timestamp::Hours(1).into(),
            humidity: 30,
            wind_direction: String::from("north"),
        }
        .into_query("weather"),
        WeatherReading {
            time: Timestamp::Hours(2).into(),
            humidity: 40,
            wind_direction: String::from("west"),
        }
        .into_query("weather"),
    ];

    client.query(weather_readings).await?;

    // Let's see if the data we wrote is there
    let read_query = ReadQuery::new("SELECT * FROM weather");

    let read_result = client.query(read_query).await?;
    println!("{}", read_result);
    Ok(())
}

For further examples, check out the Integration Tests in tests/integration_tests.rs in the repository.

Choice of HTTP backend

To communicate with InfluxDB, you can choose the HTTP backend to be used configuring the appropriate feature. We recommend sticking with the default reqwest-based client, unless you really need async-std compatibility.

  • hyper (through reqwest, used by default), with rustls

    influxdb = { version = "0.7.2", features = ["derive"] }
    
  • hyper (through reqwest), with native TLS (OpenSSL)

    influxdb = { version = "0.7.2", default-features = false,features = ["derive", "use-serde", "reqwest-client"] }
    
  • hyper (through surf), use this if you need tokio 0.2 compatibility

    influxdb = { version = "0.7.2", default-features = false,features = ["derive", "use-serde", "hyper-client"] }
    
  • curl, using libcurl

    influxdb = { version = "0.7.2", default-features = false,features = ["derive", "use-serde", "curl-client"] }
    
  • async-h1 with native TLS (OpenSSL)

    influxdb = { version = "0.7.2", default-features = false,features = ["derive", "use-serde", "h1-client"] }
    
  • async-h1 with rustls

    influxdb = { version = "0.7.2", default-features = false,features = ["derive", "use-serde", "h1-client-rustls"] }
    
  • WebAssembly’s window.fetch, via web-sys and wasm-bindgen

    influxdb = { version = "0.7.2", default-features = false,features = ["derive", "use-serde", "wasm-client"] }
    

License

License: MIT

@ 2020 Gero Gerke and contributors.

Dependencies

~4–24MB
~399K SLoC