influxc/
lib.rs

1/*!
2# InfluxDB Client Library
3
4## About this crate
5
6### What this crate provides
7
8- Support for InfluxDB 2.x.
9- Backlog storage of Record's on failure to commit due to connectivity or configuration issues.
10- Build-in compression of requests.
11
12### What it does not provide
13
14- Support for InfluxDB 1.x
15
16### What is on the roadmap
17
18- Support for async/await as a feature. [#3](https://github.com/voipir/rust-influxc/issues/3)
19- Reduction of dependencies by switching the underlying reqwest library with hyper. [#4](https://github.com/voipir/rust-influxc/issues/4)
20- Support for sending, processing responses to queries. [#5](https://github.com/voipir/rust-influxc/issues/5)
21- Support for mapping native types to query response data like sqlx. [#6](https://github.com/voipir/rust-influxc/issues/6)
22
23## Basic Usage
24
25```rust
26use influxc::Client;
27use influxc::FileBacklog;
28
29use influxc::Record;
30use influxc::Precision;
31use influxc::Credentials;
32use influxc::InfluxError;
33
34use std::time::Duration;
35use std::thread::sleep;
36
37fn main() -> Result<(), InfluxError>
38{
39    let creds   = Credentials::from_basic("testuser", "testpasswd");
40    let backlog = FileBacklog::new("./ignore/backlog")?;
41
42    let mut client = Client::build("http://127.0.0.1:8086".into(), creds)
43        .backlog(backlog)
44        .finish()?;
45
46    let mut rec = Record::new("org", "bucket")
47        .precision(Precision::Milliseconds);
48
49    loop
50    {
51        rec.measurement("sensor1")
52            .tag("floor", "second")
53            .tag("exposure", "west")
54            .field("temp", 123)
55            .field("brightness", 500);
56
57        rec.measurement("sensor2")
58            .tag("floor", "second")
59            .tag("exposure", "east")
60            .field("temp", 321)
61            .field("brightness", 999);
62
63        if let Err(e) = client.write(&rec) {
64            eprintln!("{}", e);
65        }
66
67        sleep(Duration::from_secs(1));
68    }
69}
70```
71
72*/
73#![deny(missing_docs)]
74
75#![allow(clippy::new_without_default)]
76#![allow(clippy::suspicious_else_formatting)]
77
78// Imports
79#[macro_use] extern crate log;
80#[macro_use] extern crate serde;
81
82use serde::Deserialize;
83
84use flate2::GzBuilder   as FlateGzipBuilder;
85use flate2::Compression as FlateLevel;
86
87use serde_json as json;
88use serde_json::error::Error as JsonError;
89
90use base32 as b32;
91use base64 as b64;
92
93use reqwest::Url    as ReqwUrl;
94use reqwest::Error  as ReqwError;
95use reqwest::Method as ReqwMethod;
96
97use reqwest::blocking::Client         as ReqwClient;
98use reqwest::blocking::RequestBuilder as ReqwRequestBuilder;
99
100type Utc      = chrono::Utc;
101type DateTime = chrono::DateTime<chrono::Utc>;
102
103// Internals/Exports
104mod auth;
105mod error;
106mod value;
107mod client;
108mod record;
109mod builder;
110mod precision;
111mod backlogging;
112mod measurement;
113
114use error::InfluxResult;
115use error::InfluxErrorAnnotate;
116
117use error::ApiDelayError;
118use error::ApiGenericError;
119use error::ApiOversizeError;
120use error::ApiMalformationError;
121
122pub use auth::Credentials;
123
124pub use error::InfluxError;
125
126pub use value::Value;
127
128pub use client::Client;
129
130pub use record::Record;
131
132pub use builder::ClientBuilder;
133
134pub use precision::Precision;
135
136pub use backlogging::Backlog;
137pub use backlogging::FileBacklog;
138pub use backlogging::NoopBacklog;
139
140pub use measurement::Measurement;