1 个不稳定版本
0.7.3-beta.1 | 2024年3月8日 |
---|
#619 在 解析器实现
每月下载量 23
用于 4 个 crate(通过 wind_tunnel_instruments)
85KB
1.5K SLoC
非官方 InfluxDB 驱动程序 for Rust
欢迎提交拉取请求。请参阅 贡献指南 和 行为准则。有关过去更改的列表,请参阅 CHANGELOG.md。
当前支持的功能
- 读取和写入 InfluxDB
- 可选 Serde 反序列化支持
- 在一次请求中运行多个查询(例如
SELECT * FROM weather_berlin; SELECT * FROM weather_london
) - 在一次请求中写入单个或多个度量值(例如
WriteQuery
或Vec<WriteQuery>
参数) - 认证和不认证连接
async
/await
支持#[derive(InfluxDbWriteable)]
派生宏,用于在结构体中写入/读取GROUP BY
支持- 支持 Tokio 和 async-std(见下面的示例)或 可用的后端
- 可替换的 HTTP 后端(见下文)
快速入门
将以下内容添加到您的 Cargo.toml
influxdb = { version = "0.7.2", features = ["derive"] }
有关使用 Serde 反序列化的示例,请参阅 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 `https://127.0.0.1:8086`
let client = Client::new("https://127.0.0.1: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(())
}
有关更多示例,请查看存储库中的 tests/integration_tests.rs
中的集成测试。
HTTP 后端的选择
要与 InfluxDB 通信,您可以通过配置适当的特性来选择要使用的 HTTP 后端。除非您确实需要 async-std 兼容性,否则我们建议使用默认的基于 reqwest 的客户端。
-
hyper(通过reqwest,默认使用),配合 rustls
influxdb = { version = "0.7.2", features = ["derive"] }
-
hyper(通过reqwest),使用本地TLS(OpenSSL)
influxdb = { version = "0.7.2", default-features = false, features = ["derive", "serde", "reqwest-client-native-tls"] }
-
hyper(通过reqwest),使用供应商本地TLS(OpenSSL)
influxdb = { version = "0.7.2", default-features = false, features = ["derive", "serde", "reqwest-client-native-tls-vendored"] }
-
hyper(通过surf),如果您需要tokio 0.2兼容性,请使用此版本
influxdb = { version = "0.7.2", default-features = false, features = ["derive", "serde", "hyper-client"] }
-
influxdb = { version = "0.7.2", default-features = false, features = ["derive", "serde", "curl-client"] }
-
async-h1 使用本地TLS(OpenSSL)
influxdb = { version = "0.7.2", default-features = false, features = ["derive", "serde", "h1-client"] }
-
influxdb = { version = "0.7.2", default-features = false, features = ["derive", "serde", "h1-client-rustls"] }
-
WebAssembly的
window.fetch
,通过web-sys
和 wasm-bindgeninfluxdb = { version = "0.7.2", default-features = false, features = ["derive", "serde", "wasm-client"] }
许可证
@ 2020-2024 Gero Gerke, msrd0 和 贡献者。
依赖关系
~4–24MB
~400K SLoC