use crate::{SchemaStatementBuilder, backend::SchemaBuilder, types::*};
#[derive(Default, Debug, Clone)]
pub struct TableDropStatement {
pub(crate) tables: Vec<TableRef>,
pub(crate) options: Vec<TableDropOpt>,
pub(crate) if_exists: bool,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum TableDropOpt {
Restrict,
Cascade,
}
impl TableDropStatement {
pub fn new() -> Self {
Self::default()
}
pub fn table<T>(&mut self, table: T) -> &mut Self
where
T: IntoTableRef,
{
self.tables.push(table.into_table_ref());
self
}
pub fn if_exists(&mut self) -> &mut Self {
self.if_exists = true;
self
}
pub fn restrict(&mut self) -> &mut Self {
self.options.push(TableDropOpt::Restrict);
self
}
pub fn cascade(&mut self) -> &mut Self {
self.options.push(TableDropOpt::Cascade);
self
}
pub fn take(&mut self) -> Self {
Self {
tables: std::mem::take(&mut self.tables),
options: std::mem::take(&mut self.options),
if_exists: self.if_exists,
}
}
}
impl SchemaStatementBuilder for TableDropStatement {
fn build<T: SchemaBuilder>(&self, schema_builder: T) -> String {
let mut sql = String::with_capacity(256);
schema_builder.prepare_table_drop_statement(self, &mut sql);
sql
}
}
impl TableDropStatement {
pub fn build<T: SchemaBuilder>(&self, schema_builder: T) -> String {
<Self as SchemaStatementBuilder>::build(self, schema_builder)
}
pub fn to_string<T: SchemaBuilder>(&self, schema_builder: T) -> String {
<Self as SchemaStatementBuilder>::to_string(self, schema_builder)
}
}