cql3_parser/
create_type.rs

1use crate::common::{ColumnDefinition, FQName};
2use itertools::Itertools;
3use std::fmt::{Display, Formatter};
4
5/// The data for a `CREATE TYPE` statement.
6#[derive(PartialEq, Debug, Clone)]
7pub struct CreateType {
8    /// only if the type does not exist.
9    pub not_exists: bool,
10    /// the name of the type
11    pub name: FQName,
12    /// the definition of the type.
13    pub columns: Vec<ColumnDefinition>,
14}
15
16impl Display for CreateType {
17    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
18        write!(
19            f,
20            "CREATE TYPE {}{} ({})",
21            if self.not_exists {
22                "IF NOT EXISTS "
23            } else {
24                ""
25            },
26            self.name,
27            self.columns.iter().map(|x| x.to_string()).join(", "),
28        )
29    }
30}