Skip to main content

Client

Struct Client 

Source
pub struct Client<'fd> { /* private fields */ }
Expand description

Active blocking ClickHouse connection.

Client owns C connection, I/O transport, and optional compression codec.

Implementations§

Source§

impl<'fd> Client<'fd>

Source

pub fn init<I: Io + Send + 'fd>( opts: &ClientOpts, alloc: Allocator, io: Pin<Box<I>>, codec: Option<Pin<Box<Codec>>>, ) -> Result<Self>

Creates client and completes Hello handshake using supplied transport.

Method takes ownership of io and codec. io can be PosixIo, tls::TlsIo, or custom Io implementation.

codec can be None only when compression is disabled.

Server rejection returns ErrorKind::Server carrying exception code, class, and untruncated message.

Lifetime 'fd prevents client from outliving a borrowed file descriptor:

ⓘ
use clickhouse_c::{Allocator, Client, ClientOpts, PosixIo};
use std::net::TcpStream;
use std::os::fd::AsFd;

fn build() -> clickhouse_c::Result<Client<'static>> {
    let sock = TcpStream::connect("localhost:9000")?;
    let io = PosixIo::new(sock.as_fd());
    // Borrowed socket cannot produce Client<'static>.
    Client::init(&ClientOpts::new(), Allocator::stdlib(), io, None)
}
Source

pub fn server_info(&self) -> Option<ServerInfo>

Returns server information received during handshake.

Source

pub fn set_read_timeout(&mut self, timeout: Option<Duration>) -> Result<()>

Sets transport read timeout.

PosixIo uses an absolute deadline. Set timeout again before each operation that requires a fresh deadline.

Source

pub fn send_query(&mut self, sql: &str, query_id: Option<&str>) -> Result<()>

Sends a query without settings or parameters.

Server profile supplies all query settings. Use QuerySetting::TEXT_TYPE_NAMES with send_query_with when profile may enable binary type names.

Source

pub fn send_query_with(&mut self, sql: &str, opts: &QueryOpts<'_>) -> Result<()>

Sends a query with settings and {name:Type} parameters.

use clickhouse_c::{QueryOpts, QueryParam, QuerySetting};
let settings = [
    QuerySetting::TEXT_TYPE_NAMES,
    QuerySetting::new("max_block_size", "8192"),
];
let params = [QueryParam::new("cutoff", "'100'")];
client.send_query_with(
    "SELECT number FROM numbers(1000) WHERE number > {cutoff:UInt64}",
    &QueryOpts::new().settings(&settings).params(&params),
)?;
Source

pub fn send_data(&mut self, builder: Option<&BlockBuilder<'_>>) -> Result<()>

Sends a Data block.

None sends empty block that ends INSERT input.

Source

pub fn send_cancel(&mut self) -> Result<()>

Sends protocol Cancel packet for active query.

Continue receiving events until Event::EndOfStream because packets already sent by server can still arrive. Use CancelToken to cancel local reads without sending a packet.

Source

pub fn send_ping(&mut self) -> Result<()>

Sends Ping packet. Server responds with Event::Pong.

Source

pub fn recv_event(&mut self) -> Result<Event>

Reads next server event and blocks until complete packet arrives.

Returned event owns block or exception payload.

Trait Implementations§

Source§

impl<'fd> Drop for Client<'fd>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<'fd> Send for Client<'fd>

Auto Trait Implementations§

§

impl<'fd> !RefUnwindSafe for Client<'fd>

§

impl<'fd> !Sync for Client<'fd>

§

impl<'fd> !UnwindSafe for Client<'fd>

§

impl<'fd> Freeze for Client<'fd>

§

impl<'fd> Unpin for Client<'fd>

§

impl<'fd> UnsafeUnpin for Client<'fd>

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.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.