clickhouse_srv/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 F: Fn(&str) -> String {
32        Self {
33            sql: f(&self.sql),
34            ..self
35        }
36    }
37}
38
39impl<T> From<T> for Query
40where T: AsRef<str>
41{
42    fn from(source: T) -> Self {
43        Self::new(source)
44    }
45}