Crate clickhouse_rs

source ·
Expand description

clickhouse-rs

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
  • UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64

Example

extern crate clickhouse_rs;
extern crate futures;

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

pub fn main() {
    let ddl = "
        CREATE TABLE IF NOT EXISTS payment (
            customer_id  UInt32,
            amount       UInt32,
            account_name String
        ) 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!["foo", "", "", "", "bar"]);

    let options = Options::new("127.0.0.1:9000".parse().unwrap())
        .with_compression();

    let pool = Pool::new(options);

    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_all("SELECT * FROM payment"))
        .and_then(move |(_, block)| {
            Ok(for row in block.rows() {
                let id: u32     = row.get("customer_id")?;
                let amount: u32 = row.get("amount")?;
                let name: &str  = row.get("account_name")?;
                println!("Found payment {}: {} {}", id, amount, name);
            })
        }).map_err(|err| eprintln!("database error: {}", err));

    tokio::run(done)
}

Structs

Clickhouse client handle.
Clickhouse connection options.
Asynchronous pool of Clickhouse connections.

Enums