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 = "postgres")]
41 Postgres(DropTableData<'until_build>),
42}
43
44impl DropTable for DropTableImpl<'_> {
45 fn if_exists(mut self) -> Self {
46 match self {
47 #[cfg(feature = "sqlite")]
48 DropTableImpl::SQLite(ref mut d) => d.if_exists = true,
49 #[cfg(feature = "postgres")]
50 DropTableImpl::Postgres(ref mut d) => d.if_exists = true,
51 };
52 self
53 }
54
55 fn build(self) -> String {
56 match self {
57 #[cfg(feature = "sqlite")]
58 DropTableImpl::SQLite(d) => format!(
59 "DROP TABLE \"{}\"{};",
60 d.name,
61 if d.if_exists { " IF EXISTS" } else { "" }
62 ),
63 #[cfg(feature = "postgres")]
64 DropTableImpl::Postgres(d) => format!(
65 "DROP TABLE \"{}\"{};",
66 d.name,
67 if d.if_exists { " IF EXISTS" } else { "" }
68 ),
69 }
70 }
71}