Struct 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 connect_tls<A: ToSocketAddrs>( destination: A, options: ClientOptions, name: ServerName<'static>, connector: &TlsConnector, ) -> Result<Self>

Connects to a specific socket address over TLS (rustls) 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

Source

pub fn subscribe_progress(&self) -> Receiver<(Uuid, Progress)>

Receive progress on the queries as they execute.

TODO: There is currently no way to retrieve the ID of a query launched with query or execute. The signature of these functions should be modified to also return an ID (and possibly directly the streaming broadcast).

Trait Implementations§

Source§

impl AsyncMigrate for Client

Source§

fn assert_migrations_table_query(migration_table_name: &str) -> String

Source§

fn get_last_applied_migration<'life0, 'life1, 'async_trait>( &'life0 mut self, migration_table_name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<Migration>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: Send + 'async_trait,

Source§

fn get_applied_migrations<'life0, 'life1, 'async_trait>( &'life0 mut self, migration_table_name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Migration>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: Send + 'async_trait,

Source§

fn migrate<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, migrations: &'life1 [Migration], abort_divergent: bool, abort_missing: bool, grouped: bool, target: Target, migration_table_name: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Report, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: Send + 'async_trait,

Source§

impl AsyncQuery<Vec<Migration>> for Client

Source§

fn query<'life0, 'life1, 'async_trait>( &'life0 mut self, query: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Migration>, <Self as AsyncTransaction>::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

impl AsyncTransaction for Client

Source§

type Error = KlickhouseError

Source§

fn execute<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, queries: &'life1 [&'life2 str], ) -> Pin<Box<dyn Future<Output = Result<usize, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate 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 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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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,

Source§

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>,

Source§

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>,

Source§

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

impl<T> ErasedDestructor for T
where T: 'static,