use std::rc::Rc;
use crate::{backend::TableBuilder, types::*, prepare::*};
#[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
}
pub fn build<T: TableBuilder>(&self, table_builder: T) -> String {
let mut sql = SqlWriter::new();
table_builder.prepare_table_drop_statement(self, &mut sql);
sql.result()
}
pub fn build_any(&self, table_builder: &dyn TableBuilder) -> String {
let mut sql = SqlWriter::new();
table_builder.prepare_table_drop_statement(self, &mut sql);
sql.result()
}
pub fn to_string<T: TableBuilder>(&self, table_builder: T) -> String {
self.build(table_builder)
}
}