1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
//! ## Clickhouse-driver
//! Asynchronous pure rust tokio-based  Clickhouse client library
//!
//! ## Quick start
//! add next lines in dependencies section of `Cargo.toml`
//!  ```toml
//!   clickhouse-driver = { version="0.1.0-alpha.1", path="../path_to_package/clickhouse-driver"}
//!   clickhouse-driver-lz4 = { version="0.1.0", path="../path_to_package/lz4a"}
//!   clickhouse-driver-cthrs = { version="0.1.0", path="../path_to_package/cityhash-rs"}
//!   ```
//! ## Supported Clickhouse data types
//! * Date | DateTime | DateTime64- read/write
//! * (U)Int(8|16|32|64) - read/write
//! * Float32 | Float64 - read/write
//! * UUID - read/write
//! * String | FixedString- read/write
//! * Ipv4 | Ipv6 - read/write
//! * Nullable(*) - read/write
//! * Decimal - read/write
//! * Enum8, Enum16 - read/write
//!
//! * LowCardinality(String) - read
//!
//! ## Connection url
//! ```url
//! tcp://[username:password@]host.name[:port]/database?paramname=paramvalue&...
//! ```
//! for example
//! ```url
//! tcp://user:default@localhost/log?ping_timout=200ms&execute_timeout=5s&query_timeout=20s&pool_max=4&compression=lz4
//! ```
//! - default port: 9000
//! - default username: "default"
//! - default database: "default"
//!
#![recursion_limit = "128"]
#![allow(clippy::unknown_clippy_lints)]
extern crate byteorder;
extern crate chrono;
extern crate chrono_tz;
#[cfg(not(feature = "cityhash_rs"))]
extern crate clickhouse_driver_cth;
#[cfg(feature = "cityhash_rs")]
extern crate clickhouse_driver_cthrs;

extern crate core;
#[macro_use]
extern crate futures;
extern crate hostname;
#[macro_use]
extern crate lazy_static;
#[cfg(lz4)]
extern crate clickhouse_driver_lz4a;
extern crate log;
extern crate parking_lot;
#[cfg(test)]
extern crate rand;
extern crate thiserror;
extern crate tokio;
extern crate url;
extern crate uuid;
use pool::options::Options;

#[cfg(not(target_endian = "little"))]
compile_error!("only little-endian platforms supported");

mod client;
mod compression;
mod errors;
mod pool;
pub mod prelude;
#[macro_use]
mod protocol;
mod sync;
mod types;

#[allow(dead_code)]
const MAX_STRING_LEN: usize = 64 * 1024;
/// Max number of rows in server block, 640K is default value
const MAX_BLOCK_SIZE: usize = 640 * 1024;
/// Max size of server block, bytes, 1M is default value
const MAX_BLOCK_SIZE_BYTES: usize = 10 * 1024 * 1024;

pub static CLIENT_NAME: &str = "Rust Native Driver";
pub const CLICK_HOUSE_REVISION: u64 = 54405;
pub const CLICK_HOUSE_DBMSVERSION_MAJOR: u64 = 1;
pub const CLICK_HOUSE_DBMSVERSION_MINOR: u64 = 1;

lazy_static! {
    static ref HOSTNAME: String = {
        hostname::get().map_or_else(
            |_orig| String::new(),
            |s| s.into_string().unwrap_or_default(),
        )
    };
    static ref DEF_OPTIONS: Options = crate::pool::options::Options::default();
}

pub fn description() -> String {
    format!(
        "{} {}.{}.{}",
        CLIENT_NAME,
        CLICK_HOUSE_DBMSVERSION_MAJOR,
        CLICK_HOUSE_DBMSVERSION_MINOR,
        CLICK_HOUSE_REVISION
    )
}

#[test]
fn test_encoder() {
    assert_eq!(description(), "Rust Native Driver 1.1.54405");
}