use clickhouse::Client;
pub struct ClickHouseExecutor {
client: Client,
default_database: Option<String>,
require_order_by: bool,
}
impl ClickHouseExecutor {
pub fn new(url: &str) -> Self {
Self::from_client(Client::default().with_url(url))
}
pub fn from_client(client: Client) -> Self {
Self {
client,
default_database: None,
require_order_by: true,
}
}
pub fn with_database(mut self, database: &str) -> Self {
self.client = self.client.with_database(database);
self.default_database = Some(database.to_string());
self
}
pub fn with_user(mut self, user: &str) -> Self {
self.client = self.client.with_user(user);
self
}
pub fn with_password(mut self, password: &str) -> Self {
self.client = self.client.with_password(password);
self
}
pub fn allow_unordered_tables(mut self) -> Self {
self.require_order_by = false;
self
}
pub(super) fn client(&self) -> &Client {
&self.client
}
pub(super) fn default_database(&self) -> Option<&str> {
self.default_database.as_deref()
}
pub(super) fn require_order_by(&self) -> bool {
self.require_order_by
}
}