#clickhouse #yandex #client #query #column #row

klickenhaus

A simple client library for Yandex ClickHouse

4 releases

0.1.3 Feb 20, 2019
0.1.2 Feb 19, 2019
0.1.1 Feb 3, 2019
0.1.0 Feb 3, 2019

#15 in #yandex

22 downloads per month

MIT license

37KB
476 lines

Simple Yandex ClickHouse client

How to use:

use klickenhaus::ClickhouseClient;

let ch = ClickhouseClient::new("http://localhost:8123");
assert!(ch.ping());
ch.query("DROP TABLE IF EXISTS test_table").expect("query failed");
ch.query("CREATE TABLE IF NOT EXISTS test_table (a Int32, b Enum8('a' = 1, 'b' = 2), c String, d Array(String)) ENGINE=Log").expect("query failed");
ch.query("INSERT INTO test_table (a, b, c, d) VALUES (10, 'a', 'test', ['abc', 'def']), (20, 'b', 'test2\ttest3\ntest4\rtest5', ['a\r\rbc', 'def', 'efg'])").expect("query failed");
ch.insert("INSERT INTO test_table (a, b, c, d)")
// Insert by columns
    .column(vec![50, 60, 70, 80])
    .column(vec!["a", "b", "a", "b"])
    .column(vec!["str1", "str2", "str3", "str4"])
    .column(vec![vec!["aaa", "bbb", "ccc"], vec!["ee", "ffff"], vec![], vec!["yo"]])
// Or rows
    .row((90, "a", "string", vec!["1", "2", "3"])).expect("can't insert row")
    .exec().expect("query failed");
assert_eq!(7, ch.select_row("SELECT count(*) FROM test_table").expect("query")[0].parse::<u32>().expect("count value"));
for row in ch.select("SELECT * FROM test_table").expect("query failed") {
    println!("'{}', '{}', '{}', {}", &row[0], &row[1], &row[2], &row[3]);
}
ch.query("DROP TABLE test_table").expect("query failed");

Dependencies

~20MB
~429K SLoC