Struct influxdb::Client

source ·
pub struct Client { /* private fields */ }
Expand description

Internal Representation of a Client

Implementations§

source§

impl Client

source

pub fn new<S1, S2>(url: S1, database: S2) -> Self
where S1: Into<String>, S2: Into<String>,

Instantiates a new Client

§Arguments
  • url: The URL where InfluxDB is running (ex. http://localhost:8086).
  • database: The Database against which queries and writes will be run.
§Examples
use influxdb::Client;

let _client = Client::new("http://localhost:8086", "test");
source

pub fn with_auth<S1, S2>(self, username: S1, password: S2) -> Self
where S1: Into<String>, S2: Into<String>,

Add authentication/authorization information to Client

§Arguments
  • username: The Username for InfluxDB.
  • password: The Password for the user.
§Examples
use influxdb::Client;

let _client = Client::new("http://localhost:9086", "test").with_auth("admin", "password");
source

pub fn with_http_client(self, http_client: HttpClient) -> Self

Replaces the HTTP Client

source

pub fn with_token<S>(self, token: S) -> Self
where S: Into<String>,

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 .

source

pub fn database_name(&self) -> &str

Returns the name of the database the client is using

source

pub fn database_url(&self) -> &str

Returns the URL of the InfluxDB installation the client is using

source

pub async fn ping(&self) -> Result<(String, String), Error>

Pings the InfluxDB Server

Returns a tuple of build type and version number

source

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
§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.

source§

impl Client

source

pub async fn json_query( &self, q: ReadQuery ) -> Result<DatabaseQueryResult, Error>

Trait Implementations§

source§

impl Clone for Client

source§

fn clone(&self) -> Client

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Client

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more