Struct klickhouse::Client

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

Client handle for a Clickhouse connection, has internal reference to connection, and can be freely cloned and sent across threads.

Implementations§

source§

impl Client

source

pub async fn connect_stream(
    read: impl AsyncRead + Unpin + Send + Sync + 'static,
    writer: impl AsyncWrite + Unpin + Send + Sync + 'static,
    options: ClientOptions
) -> Result<Self>

Consumes a reader and writer to connect to Klickhouse. To be used for exotic setups or TLS. Generally prefer Client::connect()

source

pub async fn connect<A: ToSocketAddrs>(
    destination: A,
    options: ClientOptions
) -> Result<Self>

Connects to a specific socket address over plaintext TCP for Clickhouse.

source

pub async fn query_raw(
    &self,
    query: impl TryInto<ParsedQuery, Error = KlickhouseError>
) -> Result<impl Stream<Item = Result<Block>>>

Sends a query string and read column blocks over a stream. You probably want Client::query()

source

pub async fn insert_native_raw(
    &self,
    query: impl TryInto<ParsedQuery, Error = KlickhouseError>,
    blocks: impl Stream<Item = Block> + Send + Sync + Unpin + 'static
) -> Result<impl Stream<Item = Result<Block>>>

Sends a query string with streaming associated data (i.e. insert) over native protocol. Once all outgoing blocks are written (EOF of blocks stream), then any response blocks from Clickhouse are read. You probably want Client::insert_native.

source

pub async fn insert_native<T: Row + Send + Sync + 'static>(
    &self,
    query: impl TryInto<ParsedQuery, Error = KlickhouseError>,
    blocks: impl Stream<Item = Vec<T>> + Send + Sync + Unpin + 'static
) -> Result<()>

Sends a query string with streaming associated data (i.e. insert) over native protocol. Once all outgoing blocks are written (EOF of blocks stream), then any response blocks from Clickhouse are read and DISCARDED. Make sure any query you send native data with has a format native suffix.

source

pub async fn insert_native_block<T: Row + Send + Sync + 'static>(
    &self,
    query: impl TryInto<ParsedQuery, Error = KlickhouseError>,
    blocks: Vec<T>
) -> Result<()>

Wrapper over Client::insert_native to send a single block. Make sure any query you send native data with has a format native suffix.

source

pub async fn query<T: Row>(
    &self,
    query: impl TryInto<ParsedQuery, Error = KlickhouseError>
) -> Result<impl Stream<Item = Result<T>>>

Runs a query against Clickhouse, returning a stream of deserialized rows. Note that no rows are returned until Clickhouse sends a full block (but it usually sends more than one block).

source

pub async fn query_collect<T: Row>(
    &self,
    query: impl TryInto<ParsedQuery, Error = KlickhouseError>
) -> Result<Vec<T>>

Same as query, but collects all rows into a Vec

source

pub async fn query_one<T: Row>(
    &self,
    query: impl TryInto<ParsedQuery, Error = KlickhouseError>
) -> Result<T>

Same as query, but returns the first row and discards the rest.

source

pub async fn query_opt<T: Row>(
    &self,
    query: impl TryInto<ParsedQuery, Error = KlickhouseError>
) -> Result<Option<T>>

Same as query, but returns the first row, if any, and discards the rest.

source

pub async fn execute(
    &self,
    query: impl TryInto<ParsedQuery, Error = KlickhouseError>
) -> Result<()>

Same as query, but discards all returns blocks. Waits until the first block returns from the server to check for errors. Waiting for the first response block or EOS also prevents the server from aborting the query potentially due to client disconnection.

source

pub async fn execute_now(
    &self,
    query: impl TryInto<ParsedQuery, Error = KlickhouseError>
) -> Result<()>

Same as execute, but doesn’t wait for a server response. The query could get aborted if the connection is closed quickly.

source

pub fn is_closed(&self) -> bool

true if the Client is closed

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

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere
    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 Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.