databend_common_ast/ast/statements/
catalog.rs1use std::collections::BTreeMap;
16use std::fmt::Display;
17use std::fmt::Formatter;
18
19use derive_visitor::Drive;
20use derive_visitor::DriveMut;
21
22use crate::ast::write_comma_separated_string_map;
23use crate::ast::CatalogType;
24use crate::ast::Identifier;
25use crate::ast::ShowLimit;
26
27#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
28pub struct ShowCatalogsStmt {
29 pub limit: Option<ShowLimit>,
30}
31
32impl Display for ShowCatalogsStmt {
33 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
34 write!(f, "SHOW CATALOGS")?;
35 if let Some(limit) = &self.limit {
36 write!(f, " {}", limit)?
37 }
38
39 Ok(())
40 }
41}
42
43#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
44pub struct ShowCreateCatalogStmt {
45 pub catalog: Identifier,
46}
47
48impl Display for ShowCreateCatalogStmt {
49 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
50 write!(f, "SHOW CREATE CATALOG {}", &self.catalog)
51 }
52}
53
54#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
55pub struct CreateCatalogStmt {
56 pub if_not_exists: bool,
57 pub catalog_name: String,
58 pub catalog_type: CatalogType,
59 pub catalog_options: BTreeMap<String, String>,
60}
61
62impl Display for CreateCatalogStmt {
63 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
64 write!(f, "CREATE CATALOG")?;
65 if self.if_not_exists {
66 write!(f, " IF NOT EXISTS")?;
67 }
68 write!(f, " {}", self.catalog_name)?;
69 write!(f, " TYPE={}", self.catalog_type)?;
70 write!(f, " CONNECTION = ( ")?;
71 write_comma_separated_string_map(f, &self.catalog_options)?;
72 write!(f, " )")
73 }
74}
75
76#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
77pub struct DropCatalogStmt {
78 pub if_exists: bool,
79 pub catalog: Identifier,
80}
81
82impl Display for DropCatalogStmt {
83 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
84 write!(f, "DROP CATALOG ")?;
85 if self.if_exists {
86 write!(f, "IF EXISTS ")?;
87 }
88 write!(f, "{}", self.catalog)
89 }
90}