Crate klickhouse
source ·Expand description
§Klickhouse
Klickhouse is a pure Rust SDK for working with Clickhouse with the native protocol in async environments with minimal boilerplate and maximal performance.
§Example Usage
See example usage.
§Unsupported Features
- Clickhouse
Enum8
andEnum16
types – useLowCardinality
instead.
§Running the tests
A Clickhouse server is required to run the integration tests. One can be started easily in a Docker container:
$ docker run --rm --name clickhouse -p 19000:9000 --ulimit nofile=262144:262144 clickhouse
$ export KLICKHOUSE_TEST_ADDR=127.0.0.1:19000
$ # export KLICKHOUSE_TEST_USER=default
$ # export KLICKHOUSE_TEST_PASSWORD=default
$ # export KLICKHOUSE_TEST_DATABASE=default
$ cargo nextest run
(running the tests simultaneously with cargo test
is currently not suported, due to loggers initializations.)
§Feature flags
derive
: Enable klickhouse_derive, providing a derive macro for the Row trait. Default.compression
:lz4
compression for client/server communication. Default.serde
: Derivation of serde::Serialize and serde::Deserialize on various objects, and JSON support. Default.tls
: TLS support via tokio-rustls.refinery
: Migrations via refinery.geo-types
: Conversion of geo types to/from the geo-types crate.bb8
: Enables aConnectionManager
managed by bb8
§Credit
klickhouse_derive
was made by copy/paste/simplify of serde_derive
to get maximal functionality and performance at lowest time-cost. In a prototype, serde
was directly used, but this was abandoned due to lock-in of serde
’s data model.
Modules§
Structs§
- Wrapper over Vec
to allow more efficient serialization/deserialization of raw bytes The corresponding Clickhouse type here is String or FixedString, not Array(UInt8). Conversion to Array(UInt8) will happen, but it is not efficient. - A hack implementation of a global lock for things like migrations
- Client handle for a Clickhouse connection, has internal reference to connection, and can be freely cloned and sent across threads.
- Options set for a Clickhouse connection.
- Wrapper for Client to use migrations on clusters
- Wrapper type for Clickhouse
Date
type. - Wrapper type for Clickhouse
DateTime
type. - Wrapper type for Clickhouse
DateTime64
type. - Wrapper type for Clickhouse
DateTime64
type with dynamic precision. - Wrapper type for Clickhouse
FixedPoint32
type. - Wrapper type for Clickhouse
FixedPoint64
type. - Wrapper type for Clickhouse
FixedPoint128
type. - Wrapper type for Clickhouse
FixedPoint256
type. - A hash table where the iteration order of the key-value pairs is independent of the hash values of the keys.
- Wrapper type for Clickhouse
IPv4
type. - Wrapper type for Clickhouse
IPv6
type. - A
Vec
wrapper that is encoded as a tuple in SQL as opposed to a Vec - Union of polygons.
- Geo point, represented by its x and y coordinates.
- Polygon with holes. The first element is the outer polygon, and the following ones are the holes.
- Query execution progress. Values are delta and must be summed.
- A row of raw data returned from the database by a query. Or an unstructured runtime-defined row to upload to the server.
- Polygon without holes.
- A single column row
- A Universally Unique Identifier (UUID).
- A
Vec
wrapper that is encoded as a tuple in SQL as opposed to a Vec - Wrapper type for Clickhouse
Int256
type. - Wrapper type for Clickhouse
UInt256
type.
Enums§
- A raw Clickhouse type.
- TimeZones built at compile time from the tz database
- A raw Clickhouse value. Types are not strictly/completely preserved (i.e. types
String
andFixedString
both are valueString
). Use this if you want dynamically typed queries.
Constants§
- Clickhouse major version
- Clickhouse minor version
Traits§
- A type that can be converted from a raw Clickhouse SQL value.
- A row that can be deserialized and serialized from a raw Clickhouse SQL value. Generally this is not implemented manually, but using
klickhouse_derive::Row
. I.e.#[derive(klickhouse::Row)]
. - A type that can be converted to a raw Clickhouse SQL value.
Functions§
Type Aliases§
Derive Macros§
- Derive macro for the Row trait.