pub struct Client { /* private fields */ }
Expand description
A client containing HTTP pool.
Implementations§
Source§impl Client
impl Client
Sourcepub fn with_http_client(client: impl HttpClient) -> Self
pub fn with_http_client(client: impl HttpClient) -> Self
Creates a new client with a specified underlying HTTP client.
See HttpClient
for details.
Sourcepub fn with_url(self, url: impl Into<String>) -> Self
pub fn with_url(self, url: impl Into<String>) -> Self
Specifies ClickHouse’s url. Should point to HTTP endpoint.
§Examples
let client = Client::default().with_url("http://localhost:8123");
Sourcepub fn with_database(self, database: impl Into<String>) -> Self
pub fn with_database(self, database: impl Into<String>) -> Self
Sourcepub fn with_user(self, user: impl Into<String>) -> Self
pub fn with_user(self, user: impl Into<String>) -> Self
Specifies a user.
§Panics
If called after Client::with_access_token
.
§Examples
let client = Client::default().with_user("test");
Sourcepub fn with_password(self, password: impl Into<String>) -> Self
pub fn with_password(self, password: impl Into<String>) -> Self
Specifies a password.
§Panics
If called after Client::with_access_token
.
§Examples
let client = Client::default().with_password("secret");
Sourcepub fn with_access_token(self, access_token: impl Into<String>) -> Self
pub fn with_access_token(self, access_token: impl Into<String>) -> Self
A JWT access token to authenticate with ClickHouse.
JWT token authentication is supported in ClickHouse Cloud only.
Should not be called after Client::with_user
or Client::with_password
.
§Panics
If called after Client::with_user
or Client::with_password
.
§Examples
let client = Client::default().with_access_token("jwt");
Sourcepub fn with_compression(self, compression: Compression) -> Self
pub fn with_compression(self, compression: Compression) -> Self
Specifies a compression mode. See Compression
for details.
By default, Lz4
is used.
§Examples
let client = Client::default().with_compression(Compression::Lz4);
Sourcepub fn with_option(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_option( self, name: impl Into<String>, value: impl Into<String>, ) -> Self
Used to specify options that will be passed to all queries.
§Example
Client::default().with_option("allow_nondeterministic_mutations", "1");
Sourcepub fn with_header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_header( self, name: impl Into<String>, value: impl Into<String>, ) -> Self
Used to specify a header that will be passed to all queries.
§Example
Client::default().with_header("Cookie", "A=1");
Sourcepub fn with_product_info(
self,
product_name: impl Into<String>,
product_version: impl Into<String>,
) -> Self
pub fn with_product_info( self, product_name: impl Into<String>, product_version: impl Into<String>, ) -> Self
Specifies the product name and version that will be included in the default User-Agent header. Multiple products are supported. This could be useful for the applications built on top of this client.
§Examples
Sample default User-Agent header:
clickhouse-rs/0.12.2 (lv:rust/1.67.0, os:macos)
Sample User-Agent with a single product information:
let client = Client::default().with_product_info("MyDataSource", "v1.0.0");
MyDataSource/v1.0.0 clickhouse-rs/0.12.2 (lv:rust/1.67.0, os:macos)
Sample User-Agent with multiple products information
(NB: the products are added in the reverse order of
Client::with_product_info
calls, which could be useful to add
higher abstraction layers first):
let client = Client::default()
.with_product_info("MyDataSource", "v1.0.0")
.with_product_info("MyApp", "0.0.1");
MyApp/0.0.1 MyDataSource/v1.0.0 clickhouse-rs/0.12.2 (lv:rust/1.67.0, os:macos)