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