use crate::{
behavior::TransactionQuery,
concat::Concat,
fmt,
structure::{DropTable, DropTableParams},
utils::push_unique,
};
impl TransactionQuery for DropTable {}
impl DropTable {
pub fn as_string(&self) -> String {
let fmts = fmt::one_line();
self.concat(&fmts)
}
pub fn drop_table(mut self, table_name: &str) -> Self {
push_unique(&mut self._drop_table, table_name.trim().to_string());
self
}
pub fn drop_table_if_exists(mut self, table_name: &str) -> Self {
push_unique(&mut self._drop_table, table_name.trim().to_string());
self._if_exists = true;
self
}
pub fn debug(self) -> Self {
let fmts = fmt::multiline();
println!("{}", fmt::format(self.concat(&fmts), &fmts));
self
}
pub fn new() -> Self {
Self::default()
}
pub fn print(self) -> Self {
let fmts = fmt::one_line();
println!("{}", fmt::format(self.concat(&fmts), &fmts));
self
}
pub fn raw(mut self, raw_sql: &str) -> Self {
push_unique(&mut self._raw, raw_sql.trim().to_string());
self
}
pub fn raw_after(mut self, param: DropTableParams, raw_sql: &str) -> Self {
self._raw_after.push((param, raw_sql.trim().to_string()));
self
}
pub fn raw_before(mut self, param: DropTableParams, raw_sql: &str) -> Self {
self._raw_before.push((param, raw_sql.trim().to_string()));
self
}
}
impl std::fmt::Display for DropTable {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.as_string())
}
}
impl std::fmt::Debug for DropTable {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let fmts = fmt::multiline();
write!(f, "{}", fmt::format(self.concat(&fmts), &fmts))
}
}