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. toml [dependencies] clickhouse-rs = "*"

Supported data types

DNS

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

parameters:

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

Example

```rust 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 ( customerid UInt32, amount UInt32, accountname 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)

} ```