Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
clickhouse-native-rs
Asynchronous ClickHouse client for Rust over the native TCP protocol.
This crate continues clickhouse-rs by Mikhail Sukharev, which has not had a release since 2023. Many thanks to Mikhail and to everyone who contributed to the original project: the code base, the API and most of the type support come from there. We keep it maintained, track current ClickHouse releases and keep the API close to the original so that moving over is a rename.
Installation
[]
= "2"
The library is imported as clickhouse_native_rs:
use ;
Moving from clickhouse-rs
Change the dependency and the paths; nothing else is required.
[]
= "2"
// before
use ;
// after
use ;
Supported data types
- Bool
- UInt8, UInt16, UInt32, UInt64, UInt128, UInt256, Int8, Int16, Int32, Int64, Int128, Int256
- Float32, Float64
- Decimal(P, S) with P up to 38 (Decimal32, Decimal64, Decimal128)
- String, FixedString(N)
- Date, DateTime, DateTime64
- IPv4, IPv6, UUID
- Enum8, Enum16
- Nullable(T), Array(T), LowCardinality(T), Map(K, V), Tuple(T1, T2, ...) and named tuples
- Point, Ring, LineString, MultiLineString, Polygon, MultiPolygon, MultiPoint, read as
their tuple and array forms:
Tuple(Float64, Float64)for a point - SimpleAggregateFunction(F, T)
Connection URL
schema://user:password@host[:port]/database?param1=value1&...¶mN=valueN
parameters:
-
compression- Compression of the data the client sends (defaults tonone). Possible choices:nonelz4zstd
With
lz4orzstdthe server compresses its replies too, using the method of itsnetwork_compression_methodsetting (ZSTD by default since ClickHouse 26.11); the client reads both. Addnetwork_compression_method=lz4to the URL to ask for LZ4 replies.zstdcompresses at the level of thenetwork_zstd_compression_levelsetting (network_zstd_compression_level=1in the URL) when it is an integer from 1 to 22, and at 3, the server default since ClickHouse 26.9, otherwise. The setting itself is sent to the server unchanged. -
connection_timeout- Timeout for connection (defaults to500 ms) -
query_timeout- Timeout forQueryResult::fetch_all(defaults to180 sec);streamandstream_blocksare not limited by it. -
insert_timeout- Timeout for inserts (defaults to180 sec). -
execute_timeout- Timeout for execute (defaults to180 sec). -
keepalive- TCP keep alive timeout in milliseconds. -
nodelay- Whether to enableTCP_NODELAY(defaults totrue). -
pool_min- Lower bound of opened connections forPool(defaults to10). -
pool_max- Upper bound of opened connections forPool(defaults to20). -
ping_before_query- Ping server every time before execute any query. (defaults totrue). -
send_retries- Count of retry to send request to server. (defaults to3). -
retry_timeout- Amount of time to wait before next retry. (defaults to5 sec). -
ping_timeout- Timeout for ping (defaults to500 ms). -
alt_hosts- Comma separated list of single address host for load-balancing. -
secure- Use TLS (needs atls-*feature). -
skip_verify- Do not verify the server certificate (needs atls-*feature).
Any other parameter is sent to the server as a query setting, for example
readonly=1 or max_threads=4.
example:
tcp://user:password@host:9000/clicks?compression=lz4&ping_timeout=42ms
Optional features
Some functionality sits behind optional features to keep compile time down for the most common use cases. The following features are available.
tokio_io(enabled by default) — I/O based on Tokio.async_std— I/O based on async-std (doesn't work together withtokio_io).tls-native-tls— TLS support with native-tls (allowed only withtokio_io).tls-rustls— TLS support with rustls (allowed only withtokio_io).tls— alias fortls-native-tls.
Example
use ;
use Error;
async
Running the tests
The integration tests need a ClickHouse server. Start one with
docker compose up -d; the tests connect to localhost:9000 unless
DATABASE_URL says otherwise:
DATABASE_URL="tcp://localhost:9000?compression=lz4"
License
MIT, see LICENSE.