cql3_parser/
create_user.rs1use crate::common::Identifier;
2use std::fmt::{Display, Formatter};
3
4#[derive(PartialEq, Debug, Clone)]
6pub struct CreateUser {
7 pub name: Identifier,
9 pub password: Option<String>,
11 pub superuser: bool,
13 pub no_superuser: bool,
15 pub if_not_exists: bool,
17}
18
19impl Display for CreateUser {
20 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
21 let mut with = String::new();
22
23 if let Some(password) = &self.password {
24 with.push_str(" PASSWORD ");
25 with.push_str(password);
26 }
27 if self.superuser {
28 with.push_str(" SUPERUSER");
29 }
30 if self.no_superuser {
31 with.push_str(" NOSUPERUSER");
32 }
33 if with.is_empty() {
34 write!(
35 f,
36 "USER {}{}",
37 if self.if_not_exists {
38 "IF NOT EXISTS "
39 } else {
40 ""
41 },
42 self.name
43 )
44 } else {
45 write!(
46 f,
47 "USER {}{} WITH{}",
48 if self.if_not_exists {
49 "IF NOT EXISTS "
50 } else {
51 ""
52 },
53 self.name,
54 with
55 )
56 }
57 }
58}