#tokio #database #clickhouse

nightly clickhouse-rs

Tokio based asynchronous Yandex ClickHouse client library

13 releases

✓ Uses Rust 2018 edition

0.2.0-alpha.2 Sep 23, 2019
0.1.17 Oct 10, 2019
0.1.14 Jul 31, 2019
0.1.9 Mar 22, 2019
0.1.0 Nov 24, 2018

#92 in Database interfaces

Download history 196/week @ 2019-06-27 134/week @ 2019-07-04 241/week @ 2019-07-11 115/week @ 2019-07-18 54/week @ 2019-07-25 87/week @ 2019-08-01 62/week @ 2019-08-08 60/week @ 2019-08-15 90/week @ 2019-08-22 71/week @ 2019-08-29 79/week @ 2019-09-05 67/week @ 2019-09-12 200/week @ 2019-09-19 75/week @ 2019-09-26 100/week @ 2019-10-03

398 downloads per month

MIT license

245KB
7K SLoC

Tokio ClickHouse Client

Build Status Crate info Documentation dependency status Coverage Status

Tokio based 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/String/Date/DateTime)

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)

  • keepalive - TCP keep alive timeout in milliseconds.

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

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

  • pool_min - 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).

example:

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

Example

use clickhouse_rs::{Block, Options, 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

~6.5MB
~119K SLoC