1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use crate::common::{ColumnDefinition, FQName, PrimaryKey, WithItem};
use itertools::Itertools;
use std::fmt::{Display, Formatter};
#[derive(PartialEq, Debug, Clone)]
pub struct CreateTable {
pub if_not_exists: bool,
pub name: FQName,
pub columns: Vec<ColumnDefinition>,
pub key: Option<PrimaryKey>,
pub with_clause: Vec<WithItem>,
}
impl Display for CreateTable {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let mut v: Vec<String> = self.columns.iter().map(|x| x.to_string()).collect();
if let Some(key) = &self.key {
v.push(key.to_string());
}
write!(
f,
"{}{} ({}){}",
if self.if_not_exists {
"IF NOT EXISTS ".to_string()
} else {
"".to_string()
},
self.name,
v.join(", "),
if !self.with_clause.is_empty() {
format!(
" WITH {}",
self.with_clause.iter().map(|x| x.to_string()).join(" AND ")
)
} else {
"".to_string()
}
)
}
}