1pub trait DropTable {
5 fn if_exists(self) -> Self;
9
10 fn build(self) -> String;
14}
15
16#[derive(Debug, Copy, Clone)]
20pub struct DropTableData<'until_build> {
21 pub(crate) name: &'until_build str,
22 pub(crate) if_exists: bool,
23}
24
25#[derive(Debug)]
31pub enum DropTableImpl<'until_build> {
32 #[cfg(feature = "sqlite")]
36 SQLite(DropTableData<'until_build>),
37 #[cfg(feature = "mysql")]
41 MySQL(DropTableData<'until_build>),
42 #[cfg(feature = "postgres")]
46 Postgres(DropTableData<'until_build>),
47}
48
49impl DropTable for DropTableImpl<'_> {
50 fn if_exists(mut self) -> Self {
51 match self {
52 #[cfg(feature = "sqlite")]
53 DropTableImpl::SQLite(ref mut d) => d.if_exists = true,
54 #[cfg(feature = "mysql")]
55 DropTableImpl::MySQL(ref mut d) => d.if_exists = true,
56 #[cfg(feature = "postgres")]
57 DropTableImpl::Postgres(ref mut d) => d.if_exists = true,
58 };
59 self
60 }
61
62 fn build(self) -> String {
63 match self {
64 #[cfg(feature = "sqlite")]
65 DropTableImpl::SQLite(d) => format!(
66 "DROP TABLE {}{};",
67 d.name,
68 if d.if_exists { " IF EXISTS" } else { "" }
69 ),
70
71 #[cfg(feature = "mysql")]
72 DropTableImpl::MySQL(d) => format!(
73 "DROP TABLE {}{};",
74 d.name,
75 if d.if_exists { " IF EXISTS" } else { "" }
76 ),
77
78 #[cfg(feature = "postgres")]
79 DropTableImpl::Postgres(d) => format!(
80 "DROP TABLE \"{}\"{};",
81 d.name,
82 if d.if_exists { " IF EXISTS" } else { "" }
83 ),
84 }
85 }
86}