influxdb_rs/lib.rs
1//! # InfluxDB Client
2//! InfluxDB is an open source time series database with no external dependencies.
3//! InfluxDB can be used for metrics, performance tuning, and even machine learning
4//!
5//! ## Usage
6//!
7//!
8//! ```Rust
9//! use influxdb_rs::{Client, Point, point, points, Value, Precision};
10//! use url::Url;
11//! use std::borrow::Cow;
12//! use chrono::prelude::*;
13//!
14//! #[tokio::main]
15//! async fn main() {
16//! // default with "http://127.0.0.1:8086", db with "test"
17//! let client = Client::new(Url::parse("http://localhost:8086").unwrap(), "test_bucket", "test_org", "0123456789").await.unwrap();
18//!
19//! let now = Utc::now();
20//! let mut point = point!("test1");
21//! let point = point
22//! .add_field("foo", Value::String(Cow::from("bar".to_string())))
23//! .add_field("integer", Value::Integer(11))
24//! .add_field("float", Value::Float(22.3))
25//! .add_field("'boolean'", Value::Boolean(false))
26//! .add_timestamp(now.timestamp());
27//!
28//! let point1 = Point::new("test1")
29//! // We use Cow::From for memeory purposes
30//! .add_tag("tags", Value::String(Cow::from(String::from("\\\"fda"))))
31//! .add_tag("number", Value::Integer(12))
32//! .add_tag("float", Value::Float(12.6))
33//! .add_field("fd", Value::String(Cow::from("'3'".to_string())))
34//! .add_field("quto", Value::String(Cow::from("\\\"fda".to_string())))
35//! .add_field("quto1", Value::String(Cow::from("\"fda".to_string())));
36//!
37//! let points = points!(point1, point);
38//!
39//! // if Precision is None, the default is second
40//! // Multiple write
41//! let result = client.write_points(points, Some(Precision::Seconds), None).await;
42//!
43//! if result.is_err(){
44//! // DO SOMETHING
45//! }
46//!
47//!
48//! // NOTE: convert time from timstamp_nanos() due to to_rfc3339() doesn't convert nicely with GOLANG
49//! let flux_query = format!("from(bucket: \"test_bucket\")
50//! |> range(start: time(v: {:?}))
51//! |> filter(fn: (r) => r._measurement == \"test4\")
52//! |> yield()", now.timestamp_nanos());
53//!
54//!
55//! let query = influxdb_rs::data_model::query::ReadQuery{
56//! r#extern: None,
57//! query: flux_query,
58//! r#type: None,
59//! dialect: None,
60//! now: None,
61//!
62//! };
63//!
64//! let result = client.query(Some(query)).await;
65//!
66//! if result.is_ok(){
67//! // Prints Response Results in String
68//! println!("{:?}", result.unwrap().text().await);
69//! }
70//! }
71//! ```
72
73#![deny(warnings)]
74#![deny(missing_docs)]
75
76/// API Functions are implemented for influxdb_rs::client::Client
77pub mod client;
78/// Error module
79pub mod error;
80
81/// Serialization module
82pub(crate) mod serialization;
83
84/// Schema for influxdb api
85pub mod data_model;
86
87/// InfluxDB Version 2 API endpoints
88#[doc(hidden)]
89pub mod api;
90
91pub use client::Client;
92pub use error::Error;
93pub use data_model::data_points::{Point, Points, Precision, Value};
94
95pub use reqwest;
96
97
98/// Database driver for Rocket.rs
99#[cfg(feature = "rocket_driver")]
100pub mod rocket_driver;