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>
impl<'fd> Client<'fd>
Sourcepub fn init<I: Io + Send + 'fd>(
opts: &ClientOpts,
alloc: Allocator,
io: Pin<Box<I>>,
codec: Option<Pin<Box<Codec>>>,
) -> Result<Self>
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)
}Sourcepub fn server_info(&self) -> Option<ServerInfo>
pub fn server_info(&self) -> Option<ServerInfo>
Returns server information received during handshake.
Sourcepub fn set_read_timeout(&mut self, timeout: Option<Duration>) -> Result<()>
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.
Sourcepub fn send_query(&mut self, sql: &str, query_id: Option<&str>) -> Result<()>
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.
Sourcepub fn send_query_with(&mut self, sql: &str, opts: &QueryOpts<'_>) -> Result<()>
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(¶ms),
)?;Sourcepub fn send_data(&mut self, builder: Option<&BlockBuilder<'_>>) -> Result<()>
pub fn send_data(&mut self, builder: Option<&BlockBuilder<'_>>) -> Result<()>
Sends a Data block.
None sends empty block that ends INSERT input.
Sourcepub fn send_cancel(&mut self) -> Result<()>
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.
Sourcepub fn send_ping(&mut self) -> Result<()>
pub fn send_ping(&mut self) -> Result<()>
Sends Ping packet. Server responds with Event::Pong.
Sourcepub fn recv_event(&mut self) -> Result<Event>
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.