clickhouse_sql_parser/
table.rs1use std::fmt;
4use crate::escape_identifier;
5
6#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
7pub struct Table {
8 pub name: String,
9 pub alias: Option<String>,
10 pub schema: Option<String>,
11}
12
13impl fmt::Display for Table {
14 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
15 if let Some(ref schema) = self.schema {
16 write!(f, "{}.", escape_identifier(schema))?;
17 }
18 write!(f, "{}", escape_identifier(&self.name))?;
19 if let Some(ref alias) = self.alias {
20 write!(f, " AS {}", escape_identifier(alias))?;
21 }
22 Ok(())
23 }
24}
25
26impl<'a> From<&'a str> for Table {
27 fn from(t: &str) -> Table {
28 Table {
29 name: String::from(t),
30 alias: None,
31 schema: None,
32 }
33 }
34}
35impl<'a> From<(&'a str, &'a str)> for Table {
36 fn from(t: (&str, &str)) -> Table {
37 Table {
38 name: String::from(t.1),
39 alias: None,
40 schema: Some(String::from(t.0)),
41 }
42 }
43}
44