cql3_parser/
alter_type.rs1use crate::alter_column::AlterColumnType;
2use crate::common::{ColumnDefinition, FQName, Identifier};
3use itertools::Itertools;
4use std::fmt::{Display, Formatter};
5
6#[derive(PartialEq, Debug, Clone)]
8pub struct AlterType {
9 pub name: FQName,
11 pub operation: AlterTypeOperation,
13}
14
15impl Display for AlterType {
16 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
17 write!(f, "ALTER TYPE {} {}", self.name, self.operation)
18 }
19}
20
21#[derive(PartialEq, Debug, Clone)]
23pub enum AlterTypeOperation {
24 AlterColumnType(AlterColumnType),
26 Add(Vec<ColumnDefinition>),
28 Rename(Vec<(Identifier, Identifier)>),
30}
31
32impl Display for AlterTypeOperation {
33 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
34 match self {
35 AlterTypeOperation::AlterColumnType(column_type) => write!(f, "{}", column_type),
36 AlterTypeOperation::Add(columns) => write!(
37 f,
38 "ADD {}",
39 columns.iter().map(|x| x.to_string()).join(", ")
40 ),
41 AlterTypeOperation::Rename(pairs) => write!(
42 f,
43 "RENAME {}",
44 pairs
45 .iter()
46 .map(|(x, y)| format!("{} TO {}", x, y))
47 .join(" AND ")
48 ),
49 }
50 }
51}