#tokio #database #clickhouse

clickhouse-rs

Tokio based asynchronous Yandex ClickHouse client library

13 releases

✓ Uses Rust 2018 edition

0.1.12 May 11, 2019
0.1.11 May 2, 2019
0.1.10 Apr 6, 2019
0.1.9 Mar 22, 2019
0.1.0 Nov 24, 2018

#38 in Database interfaces

Download history 8/week @ 2019-01-25 6/week @ 2019-02-01 2/week @ 2019-02-08 2/week @ 2019-02-15 7/week @ 2019-02-22 21/week @ 2019-03-01 5/week @ 2019-03-08 13/week @ 2019-03-15 72/week @ 2019-03-22 9/week @ 2019-03-29 32/week @ 2019-04-05 23/week @ 2019-04-12 5/week @ 2019-04-19 21/week @ 2019-04-26 29/week @ 2019-05-03

81 downloads per month

MIT license

198KB
6K 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
  • Float32, Float64
  • String, FixedString(N)
  • UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64
  • Nullable(T)

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

extern crate clickhouse_rs;
extern crate futures;

use futures::Future;
use clickhouse_rs::{Pool, types::Block};

pub fn main() {
    let ddl = "
        CREATE TABLE IF NOT EXISTS payment (
            customer_id  UInt32,
            amount       UInt32,
            account_name Nullable(FixedString(3))
        ) Engine=Memory";

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

    let pool = Pool::new(database_url);
    
    let done = pool
       .get_handle()
       .and_then(move |c| c.execute(ddl))
       .and_then(move |c| c.insert("payment", block))
       .and_then(move |c| c.query("SELECT * FROM payment").fetch_all())
       .and_then(move |(_, block)| {
           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(())
       })
       .map_err(|err| eprintln!("database error: {}", err));
    tokio::run(done)
}

Dependencies

~6.5MB
~110K SLoC