use inherent::inherent;
use crate::{backend::SchemaBuilder, types::*, SchemaStatementBuilder};
#[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)]
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,
}
}
}
#[inherent]
impl SchemaStatementBuilder for TableDropStatement {
pub 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
}
pub fn build_any(&self, schema_builder: &dyn SchemaBuilder) -> String {
let mut sql = String::with_capacity(256);
schema_builder.prepare_table_drop_statement(self, &mut sql);
sql
}
pub fn to_string<T: SchemaBuilder>(&self, schema_builder: T) -> String;
}