clickhouse_client/schema/
mod.rs1mod query;
4
5pub use query::*;
6
7use crate::value::Type;
8
9#[derive(Debug)]
11pub struct TableSchema {
12 pub name: String,
14 pub columns: Vec<ColumnSchema>,
16}
17
18impl TableSchema {
19 pub fn new(name: &str) -> Self {
21 Self {
22 name: name.to_string(),
23 columns: vec![],
24 }
25 }
26
27 pub fn with_column(mut self, column: ColumnSchema) -> Self {
29 self.columns.push(column);
30 self
31 }
32
33 pub fn column(mut self, id: &str, ty: Type, primary: bool) -> Self {
35 self.columns.push(ColumnSchema::new(id, ty, primary));
36 self
37 }
38
39 pub fn add_column(&mut self, id: &str, ty: Type, primary: bool) -> &mut Self {
41 self.columns.push(ColumnSchema::new(id, ty, primary));
42 self
43 }
44
45 pub fn get_column_by_id(&self, id: &str) -> Option<&ColumnSchema> {
47 self.columns.iter().find(|c| c.id.as_str() == id)
48 }
49}
50
51#[derive(Debug, Clone)]
53pub struct ColumnSchema {
54 pub id: String,
56 pub ty: Type,
58 pub primary: bool,
60}
61
62impl ColumnSchema {
63 pub fn new(id: &str, ty: Type, primary: bool) -> Self {
65 Self {
66 id: id.to_string(),
67 ty,
68 primary,
69 }
70 }
71}