pub struct Client { /* private fields */ }Expand description
A client for performing frequent InfluxQL queries in a convenient way
use std::collections::HashMap;
use url::Url;
use rinfluxdb_influxql::QueryBuilder;
use rinfluxdb_influxql::r#async::Client;
use rinfluxdb_dataframe::DataFrame;
async_std::task::block_on(async {
let client = Client::new(
Url::parse("https://example.com/")?,
Some(("username", "password")),
)?;
let query = QueryBuilder::from("indoor_environment")
.database("house")
.field("temperature")
.field("humidity")
.build();
let dataframe: DataFrame = client.fetch_dataframe(query).await?;
println!("{}", dataframe);
let query = QueryBuilder::from("indoor_environment")
.database("house")
.field("temperature")
.field("humidity")
.group_by("room")
.build();
let tagged_dataframes: HashMap<String, DataFrame> = client.fetch_dataframes_by_tag(query, "room").await?;
for (tag, dataframe) in tagged_dataframes {
println!("{}: {}", tag, dataframe);
}
# Ok::<(), rinfluxdb_influxql::ClientError>(())
# })?;
# Ok::<(), rinfluxdb_influxql::ClientError>(())Implementations§
Source§impl Client
impl Client
Sourcepub fn new<T, S>(
base_url: Url,
credentials: Option<(T, S)>,
) -> Result<Self, ClientError>
pub fn new<T, S>( base_url: Url, credentials: Option<(T, S)>, ) -> Result<Self, ClientError>
Create a new client to an InfluxDB server
Parameter credentials can be used to provide username and password if
the server requires authentication.
Sourcepub async fn fetch_dataframe<DF, E>(
&self,
query: Query,
) -> Result<DF, ClientError>
pub async fn fetch_dataframe<DF, E>( &self, query: Query, ) -> Result<DF, ClientError>
Query the server for a single dataframe
This function assumes a single statement is returned, and that such statement contains a single dataframe. Everything else is ignored.
ClientError::EmptyError is returned if the
response does not contain
dataframes.
Sourcepub async fn fetch_dataframes_by_tag<DF, E>(
&self,
query: Query,
tag: &str,
) -> Result<HashMap<String, DF>, ClientError>
pub async fn fetch_dataframes_by_tag<DF, E>( &self, query: Query, tag: &str, ) -> Result<HashMap<String, DF>, ClientError>
Query the server for dataframes grouped by a single tag
This function assumes a single statement is returned, and that such statement contains multiple dataframe with the specified tag. Everything else is ignored.
ClientError::EmptyError is returned if the
response does not contain dataframes.
ClientError::ExpectedTagsError is
returned if the response does not contain tagged dataframes.
ClientError::ExpectedTagError is
returned if the response contains tagged dataframes, but the specified
tag is missing.