use crate::{backend::SchemaBuilder, prepare::*, types::*, SchemaStatementBuilder};
use std::rc::Rc;
#[derive(Debug, Clone)]
pub struct TableDropStatement {
pub(crate) tables: Vec<Rc<dyn Iden>>,
pub(crate) options: Vec<TableDropOpt>,
pub(crate) if_exists: bool,
}
#[derive(Debug, Clone)]
pub enum TableDropOpt {
Restrict,
Cascade,
}
impl Default for TableDropStatement {
fn default() -> Self {
Self::new()
}
}
impl TableDropStatement {
pub fn new() -> Self {
Self {
tables: Vec::new(),
options: Vec::new(),
if_exists: false,
}
}
pub fn table<T: 'static>(mut self, table: T) -> Self
where
T: Iden,
{
self.tables.push(Rc::new(table));
self
}
pub fn if_exists(mut self) -> Self {
self.if_exists = true;
self
}
pub fn restrict(mut self) -> Self {
self.options.push(TableDropOpt::Restrict);
self
}
pub fn cascade(mut self) -> Self {
self.options.push(TableDropOpt::Cascade);
self
}
}
impl SchemaStatementBuilder for TableDropStatement {
fn build<T: SchemaBuilder>(&self, schema_builder: T) -> String {
let mut sql = SqlWriter::new();
schema_builder.prepare_table_drop_statement(self, &mut sql);
sql.result()
}
fn build_any(&self, schema_builder: &dyn SchemaBuilder) -> String {
let mut sql = SqlWriter::new();
schema_builder.prepare_table_drop_statement(self, &mut sql);
sql.result()
}
}