databend_common_ast/ast/statements/
connection.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::CreateOption;
23use crate::ast::Identifier;
24
25#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
26pub struct CreateConnectionStmt {
27 pub name: Identifier,
28 pub storage_type: String,
29 pub storage_params: BTreeMap<String, String>,
30 pub create_option: CreateOption,
31}
32
33#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
34pub struct DropConnectionStmt {
35 pub if_exists: bool,
36 pub name: Identifier,
37}
38
39impl Display for DropConnectionStmt {
40 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
41 write!(f, "DROP CONNECTION ")?;
42 if self.if_exists {
43 write!(f, "IF EXISTS ")?;
44 }
45 write!(f, "{} ", self.name)
46 }
47}
48
49#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
50pub struct DescribeConnectionStmt {
51 pub name: Identifier,
52}
53
54impl Display for CreateConnectionStmt {
55 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
56 write!(f, "CREATE")?;
57 if let CreateOption::CreateOrReplace = self.create_option {
58 write!(f, " OR REPLACE")?;
59 }
60 write!(f, " CONNECTION ")?;
61 if let CreateOption::CreateIfNotExists = self.create_option {
62 write!(f, "IF NOT EXISTS ")?;
63 }
64 write!(f, "{} ", self.name)?;
65 write!(f, "STORAGE_TYPE = '{}'", self.storage_type)?;
66 for (k, v) in &self.storage_params {
67 write!(f, " {k} = '{v}'")?;
68 }
69 Ok(())
70 }
71}
72
73impl Display for DescribeConnectionStmt {
74 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
75 write!(f, "DESCRIBE CONNECTION {} ", self.name)
76 }
77}
78
79#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
80pub struct ShowConnectionsStmt {}
81
82impl Display for ShowConnectionsStmt {
83 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
84 write!(f, "SHOW CONNECTIONS")
85 }
86}