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::quote::QuotedString;
22use crate::ast::CreateOption;
23use crate::ast::Identifier;
24
25#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
26pub struct CreateSequenceStmt {
27 pub create_option: CreateOption,
28 pub sequence: Identifier,
29 pub comment: Option<String>,
30}
31
32impl Display for CreateSequenceStmt {
33 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
34 write!(f, "CREATE ")?;
35 if let CreateOption::CreateOrReplace = self.create_option {
36 write!(f, "OR REPLACE ")?;
37 }
38 write!(f, "SEQUENCE ")?;
39 if let CreateOption::CreateIfNotExists = self.create_option {
40 write!(f, "IF NOT EXISTS ")?;
41 }
42 write!(f, "{}", self.sequence)?;
43 if let Some(comment) = &self.comment {
44 write!(f, " COMMENT = {}", QuotedString(comment, '\''))?;
45 }
46 Ok(())
47 }
48}
49
50#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
51pub struct DropSequenceStmt {
52 pub if_exists: bool,
53 pub sequence: Identifier,
54}
55
56impl Display for DropSequenceStmt {
57 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
58 write!(f, "DROP SEQUENCE ")?;
59 if self.if_exists {
60 write!(f, "IF EXISTS ")?;
61 }
62 write!(f, "{}", self.sequence)?;
63 Ok(())
64 }
65}