Skip to main content

Crate clickhouse_native_client

Crate clickhouse_native_client 

Source
Expand description

§ClickHouse Native Client

A native async Rust client for ClickHouse database, ported from the C++ clickhouse-cpp library.

This crate implements the ClickHouse native TCP binary protocol with LZ4/ZSTD compression, TLS support, and all major ClickHouse data types.

§Production Readiness

Most of the codebase was created by converting the C++ clickhouse-cpp client. Although the client is already used to ingest TiBs of data a day and is relatively well covered by unit tests, there may be bugs. Test your use case before committing.

§Quick Start

use clickhouse_native_client::{Client, ClientOptions, Block};
use clickhouse_native_client::column::numeric::ColumnUInt64;
use std::sync::Arc;

// Connect to ClickHouse
let opts = ClientOptions::new("localhost", 9000)
    .database("default")
    .user("default");
let mut client = Client::connect(opts).await?;

// Execute DDL
client.execute("CREATE TABLE IF NOT EXISTS test (id UInt64) ENGINE = Memory").await?;

// Insert data
let mut col = ColumnUInt64::new();
col.append(1);
col.append(2);
let mut block = Block::new();
block.append_column("id", Arc::new(col))?;
client.insert("test", block).await?;

// Query data
let result = client.query("SELECT id FROM test").await?;
for block in result.blocks() {
    println!("rows: {}", block.row_count());
}

§Feature Flags

  • tls - Enables TLS/SSL connections via rustls and tokio-rustls.

§Modules

  • client - Async client API (Client, ClientOptions)
  • block - Data blocks (Block, BlockInfo)
  • column - Column types for all ClickHouse data types
  • query - Query builder and protocol messages
  • types - ClickHouse type system and parser
  • compression - LZ4/ZSTD compression
  • protocol - Protocol constants (packet types, revisions)
  • error - Error types and Result alias
  • connection - Async TCP/TLS connection wrapper
  • wire_format - Wire protocol encoding helpers
  • io - Block reader/writer for async I/O
  • ssl - TLS/SSL options (requires tls feature)

Re-exports§

pub use block::Block;
pub use block::BlockInfo;
pub use client::Client;
pub use client::ClientOptions;
pub use client::Endpoint;
pub use client::QueryResult;
pub use connection::ConnectionOptions;
pub use error::Error;
pub use error::Result;
pub use query::DataCallback;
pub use query::DataCancelableCallback;
pub use query::Exception;
pub use query::ExceptionCallback;
pub use query::ExternalTable;
pub use query::Profile;
pub use query::ProfileCallback;
pub use query::ProfileEventsCallback;
pub use query::Progress;
pub use query::ProgressCallback;
pub use query::Query;
pub use query::QuerySettingsField;
pub use query::ServerLogCallback;
pub use query::TracingContext;

Modules§

block
Data blocks (collections of named columns).
client
Async client API and connection options.
column
Column type implementations for all ClickHouse data types.
compression
LZ4 and ZSTD block compression. LZ4 and ZSTD block compression for the ClickHouse native protocol.
connection
Async TCP/TLS connection wrapper.
error
Error types and Result alias. Error types for the ClickHouse client.
io
Block reader/writer for async I/O. I/O module for block streaming between the client and ClickHouse server.
protocol
Protocol constants (packet types, revision numbers).
query
Query builder and protocol messages.
socket
Re-exports from the connection module. Re-exports from the connection module.
types
ClickHouse type system and type string parser.
wire_format
Wire protocol encoding helpers (varint, fixed-size types).