Expand description

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.

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)
  • Authenticated and Unauthenticated Connections
  • async/await support
  • #[derive(InfluxDbWriteable)] Derive Macro for Writing / Reading into Structs
  • GROUP BY support

Planned Features

  • Read Query Builder instead of supplying raw queries

Quickstart

Add the following to your Cargo.toml

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

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

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

#[tokio::main]
async fn main() {
    // 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,
        #[tag] wind_direction: String,
    }

    // Let's write some data into a measurement called `weather`
    let weather_reading = WeatherReading {
        time: Timestamp::Hours(1).into(),
        humidity: 30,
        wind_direction: String::from("north"),
    };

    let write_result = client
        .query(&weather_reading.into_query("weather"))
        .await;
    assert!(write_result.is_ok(), "Write result was not okay");

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

    let read_result = client.query(&read_query).await;
    assert!(read_result.is_ok(), "Read result was not ok");
    println!("{}", read_result.unwrap());
}

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

License

License: MIT

Modules

Structs

Internal Representation of a Client

Internal Representation of a Write query that has not yet been built

Enums

Internal Enum used to decide if a POST or GET request should be sent to InfluxDB. See InfluxDB Docs.

Internal enum used to represent either type of query.

Traits

Derive Macros