Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

influxdb-rs/influxdb-rust

Open more actions menu

rust-influxdb

Unofficial InfluxDB Driver for Rust

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

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]
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?;

    // Read back all records
    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", "serde", "reqwest-client-native-tls"] }
  • hyper (through reqwest), with vendored native TLS (OpenSSL)

    influxdb = { version = "0.7.2", default-features = false, features = ["derive", "serde", "reqwest-client-native-tls-vendored"] }

License

License: MIT

@ 2020-2024 Gero Gerke, msrd0 and contributors.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.