cql3_parser/
create_keyspace.rs1use crate::common::Identifier;
2use itertools::Itertools;
3use std::fmt::{Display, Formatter};
4
5#[derive(PartialEq, Debug, Clone)]
7pub struct CreateKeyspace {
8 pub name: Identifier,
10 pub replication: Vec<(String, String)>,
12 pub durable_writes: Option<bool>,
14 pub if_not_exists: bool,
16}
17
18impl Display for CreateKeyspace {
19 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
20 if let Some(durable_writes) = self.durable_writes {
21 write!(
22 f,
23 "KEYSPACE {}{} WITH REPLICATION = {{{}}} AND DURABLE_WRITES = {}",
24 if self.if_not_exists {
25 "IF NOT EXISTS "
26 } else {
27 ""
28 },
29 self.name,
30 self.replication
31 .iter()
32 .map(|(x, y)| format!("{}:{}", x, y))
33 .join(", "),
34 if durable_writes { "TRUE" } else { "FALSE" }
35 )
36 } else {
37 write!(
38 f,
39 "KEYSPACE {}{} WITH REPLICATION = {{{}}}",
40 if self.if_not_exists {
41 "IF NOT EXISTS "
42 } else {
43 ""
44 },
45 self.name,
46 self.replication
47 .iter()
48 .map(|(x, y)| format!("{}:{}", x, y))
49 .join(", ")
50 )
51 }
52 }
53}