Giter Site home page Giter Site logo

bestarch-ae / clickhouse-rs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from suharev7/clickhouse-rs

0.0 1.0 1.0 522 KB

Tokio based asynchronous ClickHouse client library for rust programming language.

License: MIT License

Rust 94.52% CMake 0.03% C++ 4.15% C 1.26% Starlark 0.04%

clickhouse-rs's Introduction

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/Float/String/Date/DateTime)
  • IPv4/IPv6
  • UUID

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
  • readonly - Restricts permissions for read data, write data and change settings queries. (defaults to none). Possible choices:

    • 0 - All queries are allowed.
    • 1 - Only read data queries are allowed.
    • 2 - Read data and change settings queries are allowed.
  • 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_min - Lower bound of opened connections for Pool (defaults to 10).

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

  • alt_hosts - Comma separated list of single address host for load-balancing.

SSL/TLS parameters:

  • secure - establish secure connection (defaults is false).
  • skip_verify - skip certificate verification (defaults is false).

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()
        .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 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)
}

clickhouse-rs's People

Contributors

suharev7 avatar jspeis avatar dingxiangfei2009 avatar athre0z avatar hwchen avatar polachok avatar gowebprod avatar l4l avatar yutiansut avatar utterstep avatar avitex avatar

Watchers

James Cloos avatar

Forkers

deniallugo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.