Crates.io | influx-client |
lib.rs | influx-client |
version | 0.4.1 |
source | src |
created_at | 2021-02-21 21:01:45.22315 |
updated_at | 2023-01-24 21:14:50.930037 |
description | A Rust library to interact with InfluxDB |
homepage | |
repository | https://github.com/ctiedt/influx_client |
max_upload_size | |
id | 358658 |
size | 54,870 |
A Rust library to interact with InfluxDB databases. It is still early in development, so expect bugs and missing features.
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(())
}