1use inherent::inherent;
2
3use crate::{backend::SchemaBuilder, types::*, SchemaStatementBuilder};
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)]
39pub enum TableDropOpt {
40 Restrict,
41 Cascade,
42}
43
44impl TableDropStatement {
45 pub fn new() -> Self {
47 Self::default()
48 }
49
50 pub fn table<T>(&mut self, table: T) -> &mut Self
52 where
53 T: IntoTableRef,
54 {
55 self.tables.push(table.into_table_ref());
56 self
57 }
58
59 pub fn if_exists(&mut self) -> &mut Self {
61 self.if_exists = true;
62 self
63 }
64
65 pub fn restrict(&mut self) -> &mut Self {
67 self.options.push(TableDropOpt::Restrict);
68 self
69 }
70
71 pub fn cascade(&mut self) -> &mut Self {
73 self.options.push(TableDropOpt::Cascade);
74 self
75 }
76
77 pub fn take(&mut self) -> Self {
78 Self {
79 tables: std::mem::take(&mut self.tables),
80 options: std::mem::take(&mut self.options),
81 if_exists: self.if_exists,
82 }
83 }
84}
85
86#[inherent]
87impl SchemaStatementBuilder for TableDropStatement {
88 pub fn build<T: SchemaBuilder>(&self, schema_builder: T) -> String {
89 let mut sql = String::with_capacity(256);
90 schema_builder.prepare_table_drop_statement(self, &mut sql);
91 sql
92 }
93
94 pub fn build_any(&self, schema_builder: &dyn SchemaBuilder) -> String {
95 let mut sql = String::with_capacity(256);
96 schema_builder.prepare_table_drop_statement(self, &mut sql);
97 sql
98 }
99
100 pub fn to_string<T: SchemaBuilder>(&self, schema_builder: T) -> String;
101}