1use inherent::inherent;
2
3use crate::{SchemaStatementBuilder, backend::SchemaBuilder, types::*};
4
5#[derive(Default, Debug, Clone)]
31pub struct TableDropStatement {
32 pub(crate) tables: Vec<TableRef>,
33 pub(crate) options: Vec<TableDropOpt>,
34 pub(crate) if_exists: bool,
35}
36
37#[derive(Debug, Clone)]
39#[non_exhaustive]
40pub enum TableDropOpt {
41 Restrict,
42 Cascade,
43}
44
45impl TableDropStatement {
46 pub fn new() -> Self {
48 Self::default()
49 }
50
51 pub fn table<T>(&mut self, table: T) -> &mut Self
53 where
54 T: IntoTableRef,
55 {
56 self.tables.push(table.into_table_ref());
57 self
58 }
59
60 pub fn if_exists(&mut self) -> &mut Self {
62 self.if_exists = true;
63 self
64 }
65
66 pub fn restrict(&mut self) -> &mut Self {
68 self.options.push(TableDropOpt::Restrict);
69 self
70 }
71
72 pub fn cascade(&mut self) -> &mut Self {
74 self.options.push(TableDropOpt::Cascade);
75 self
76 }
77
78 pub fn take(&mut self) -> Self {
79 Self {
80 tables: std::mem::take(&mut self.tables),
81 options: std::mem::take(&mut self.options),
82 if_exists: self.if_exists,
83 }
84 }
85}
86
87#[inherent]
88impl SchemaStatementBuilder for TableDropStatement {
89 pub fn build<T: SchemaBuilder>(&self, schema_builder: T) -> String {
90 let mut sql = String::with_capacity(256);
91 schema_builder.prepare_table_drop_statement(self, &mut sql);
92 sql
93 }
94
95 pub fn build_any(&self, schema_builder: &dyn SchemaBuilder) -> String {
96 let mut sql = String::with_capacity(256);
97 schema_builder.prepare_table_drop_statement(self, &mut sql);
98 sql
99 }
100
101 pub fn to_string<T: SchemaBuilder>(&self, schema_builder: T) -> String;
102}