databend_common_ast/ast/statements/
sequence.rs1use std::fmt::Display;
16use std::fmt::Formatter;
17
18use derive_visitor::Drive;
19use derive_visitor::DriveMut;
20
21use crate::ast::CreateOption;
22use crate::ast::Identifier;
23use crate::ast::quote::QuotedString;
24
25#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
26pub struct CreateSequenceStmt {
27 pub create_option: CreateOption,
28 pub sequence: Identifier,
29 pub start: Option<u64>,
30 pub increment: Option<u64>,
31 pub comment: Option<String>,
32}
33
34impl Display for CreateSequenceStmt {
35 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
36 write!(f, "CREATE ")?;
37 if let CreateOption::CreateOrReplace = self.create_option {
38 write!(f, "OR REPLACE ")?;
39 }
40 write!(f, "SEQUENCE ")?;
41 if let CreateOption::CreateIfNotExists = self.create_option {
42 write!(f, "IF NOT EXISTS ")?;
43 }
44 write!(f, "{}", self.sequence)?;
45
46 if let Some(s) = &self.start {
47 write!(f, " START = {}", s)?;
48 }
49
50 if let Some(i) = &self.increment {
51 write!(f, " INCREMENT = {}", i)?;
52 }
53 if let Some(comment) = &self.comment {
54 write!(f, " COMMENT = {}", QuotedString(comment, '\''))?;
55 }
56 Ok(())
57 }
58}
59
60#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
61pub struct DropSequenceStmt {
62 pub if_exists: bool,
63 pub sequence: Identifier,
64}
65
66impl Display for DropSequenceStmt {
67 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
68 write!(f, "DROP SEQUENCE ")?;
69 if self.if_exists {
70 write!(f, "IF EXISTS ")?;
71 }
72 write!(f, "{}", self.sequence)?;
73 Ok(())
74 }
75}