Search

Lib.rs

› Database interfaces
#tokio

clickhouse-rs

Asynchronous Yandex ClickHouse client library

by mikhail and 26 contributors

  • Install
  • API reference
  • GitHub repo (suharev7)

20 releases

1.1.0-alpha.1 Sep 10, 2023
1.0.0-alpha.1 Jan 27, 2021
0.2.0-alpha.5 Jun 9, 2020
0.2.0-alpha.4 Jan 24, 2020
0.1.0 Nov 24, 2018

#1632 in Database interfaces

Download history 398/week @ 2026-01-11 530/week @ 2026-01-18 454/week @ 2026-01-25 831/week @ 2026-02-01 753/week @ 2026-02-08 851/week @ 2026-02-15 474/week @ 2026-02-22 607/week @ 2026-03-01 1218/week @ 2026-03-08 1046/week @ 2026-03-15 1282/week @ 2026-03-22 1225/week @ 2026-03-29 947/week @ 2026-04-05 966/week @ 2026-04-12 1022/week @ 2026-04-19 641/week @ 2026-04-26

3,671 downloads per month
Used in 6 crates

MIT license

470KB
13K SLoC

Async ClickHouse Client

Build Status Crate info Documentation dependency status Coverage Status

Asynchronous Yandex ClickHouse client library for rust programming language.

Installation

Library hosted on crates.io.

[dependencies]
clickhouse-rs = "*"

Supported data types

  • Date
  • DateTime
  • Decimal(P, S)
  • Float32, Float64
  • String, FixedString(N)
  • UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64
  • Nullable(T)
  • Array(UInt/Int/Float/String/Date/DateTime)
  • SimpleAggregateFunction(F, T)
  • IPv4/IPv6
  • UUID
  • Bool

DNS

schema://user:password@host[:port]/database?param1=value1&...&paramN=valueN

parameters:

  • compression - Whether or not use compression (defaults to none). Possible choices:

    • none
    • lz4
  • connection_timeout - Timeout for connection (defaults to 500 ms)

  • query_timeout - Timeout for queries (defaults to 180 sec).

  • insert_timeout - Timeout for inserts (defaults to 180 sec).

  • execute_timeout - Timeout for execute (defaults to 180 sec).

  • keepalive - TCP keep alive timeout in milliseconds.

  • nodelay - Whether to enable TCP_NODELAY (defaults to true).

  • pool_min - Lower bound of opened connections for Pool (defaults to 10).

  • pool_max - Upper bound of opened connections for Pool (defaults to 20).

  • ping_before_query - Ping server every time before execute any query. (defaults to true).

  • send_retries - Count of retry to send request to server. (defaults to 3).

  • retry_timeout - Amount of time to wait before next retry. (defaults to 5 sec).

  • ping_timeout - Timeout for ping (defaults to 500 ms).

  • alt_hosts - Comma separated list of single address host for load-balancing.

example:

tcp://user:password@host:9000/clicks?compression=lz4&ping_timeout=42ms

Optional features

clickhouse-rs puts some functionality behind optional features to optimize compile time for the most common use cases. The following features are available.

  • tokio_io (enabled by default) — I/O based on Tokio.
  • async_std — I/O based on async-std (doesn't work together with tokio_io).
  • tls — TLS support (allowed only with tokio_io).

Example

use clickhouse_rs::{Block, Pool};
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let ddl = r"
        CREATE TABLE IF NOT EXISTS payment (
            customer_id  UInt32,
            amount       UInt32,
            account_name Nullable(FixedString(3))
        ) Engine=Memory";

    let block = Block::new()
        .column("customer_id",  vec![1_u32,  3,  5,  7,  9])
        .column("amount",       vec![2_u32,  4,  6,  8, 10])
        .column("account_name", vec![Some("foo"), None, None, None, Some("bar")]);

    let pool = Pool::new(database_url);

    let mut client = pool.get_handle().await?;
    client.execute(ddl).await?;
    client.insert("payment", block).await?;
    let block = client.query("SELECT * FROM payment").fetch_all().await?;

    for row in block.rows() {
        let id: u32             = row.get("customer_id")?;
        let amount: u32         = row.get("amount")?;
        let name: Option<&str>  = row.get("account_name")?;
        println!("Found payment {}: {} {:?}", id, amount, name);
    }

    Ok(())
}

Dependencies

~13–23MB
~365K SLoC

  • async_std? async-std 1.6
  • byteorder
  • chrono+std
  • chrono-tz 0.8
  • clickhouse-rs-cityhash-sys
  • combine
  • crossbeam
  • either
  • futures-core
  • futures-sink
  • futures-util+sink
  • hostname 0.3
  • lazy_static
  • log+std+serde
  • lz4
  • tls? native-tls
  • tls? tokio-native-tls
  • percent-encoding
  • pin-project
  • thiserror 1.0
  • tokio_io tokio+io-util+time+net+sync+rt-multi-thread
  • url
  • uuid
  • dev env_logger 0.10
  • dev pretty_assertions
  • dev rand 0.8
Related: clickhouse-rs-cityhash-sys
See also: clickhouse, tokio, async-tungstenite, async-compat, tokio-serial, tokio-retry, neo4rs, async_zip, ldap3, libsql, clickhouse-arrow

Lib.rs is an unofficial list of Rust/Cargo crates, created by kornelski. It contains data from multiple sources, including heuristics, and manually curated data. Content of this page is not necessarily endorsed by the authors of the crate. This site is not affiliated with nor endorsed by the Rust Project. If something is missing or incorrect, please file a bug.