Skip to main content

clickhouse_rs/types/
query.rs

1#[derive(Clone, Debug)]
2pub struct Query {
3    sql: String,
4    id: String,
5}
6
7impl Query {
8    pub fn new(sql: impl AsRef<str>) -> Self {
9        Self {
10            sql: sql.as_ref().to_string(),
11            id: "".to_string(),
12        }
13    }
14
15    pub fn id(self, id: impl AsRef<str>) -> Self {
16        Self {
17            id: id.as_ref().to_string(),
18            ..self
19        }
20    }
21
22    pub(crate) fn get_sql(&self) -> &str {
23        &self.sql
24    }
25
26    pub(crate) fn get_id(&self) -> &str {
27        &self.id
28    }
29
30    pub(crate) fn map_sql<F>(self, f: F) -> Self
31    where
32        F: Fn(&str) -> String,
33    {
34        Self {
35            sql: f(&self.sql),
36            ..self
37        }
38    }
39}
40
41impl<T> From<T> for Query
42where
43    T: AsRef<str>,
44{
45    fn from(source: T) -> Self {
46        Self::new(source)
47    }
48}