pub struct Client { /* private fields */ }
Expand description
Internal Representation of a Client
Implementations§
Source§impl Client
impl Client
Sourcepub fn with_http_client(self, http_client: HttpClient) -> Self
pub fn with_http_client(self, http_client: HttpClient) -> Self
Replaces the HTTP Client
Sourcepub fn with_token<S>(self, token: S) -> Self
pub fn with_token<S>(self, token: S) -> Self
Add authorization token to Client
This is designed for influxdb 2.0’s backward-compatible API which requires authorization by default. You can create such token from console of influxdb 2.0 .
Sourcepub fn database_name(&self) -> &str
pub fn database_name(&self) -> &str
Returns the name of the database the client is using
Sourcepub fn database_url(&self) -> &str
pub fn database_url(&self) -> &str
Returns the URL of the InfluxDB installation the client is using
Sourcepub async fn ping(&self) -> Result<(String, String), Error>
pub async fn ping(&self) -> Result<(String, String), Error>
Pings the InfluxDB Server
Returns a tuple of build type and version number
Sourcepub async fn query<Q>(&self, q: Q) -> Result<String, Error>where
Q: Query,
pub async fn query<Q>(&self, q: Q) -> Result<String, Error>where
Q: Query,
Sends a ReadQuery
or WriteQuery
to the InfluxDB Server.
A version capable of parsing the returned string is available under the serde_integration
§Arguments
q
: Query of typeReadQuery
orWriteQuery
§Examples
use influxdb::{Client, Query, Timestamp};
use influxdb::InfluxDbWriteable;
use std::time::{SystemTime, UNIX_EPOCH};
let start = SystemTime::now();
let since_the_epoch = start
.duration_since(UNIX_EPOCH)
.expect("Time went backwards")
.as_millis();
let client = Client::new("http://localhost:8086", "test");
let query = Timestamp::Milliseconds(since_the_epoch)
.into_query("weather")
.add_field("temperature", 82);
let results = client.query(query).await?;
§Errors
If the function can not finish the query,
a Error
variant will be returned.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more