toasty_sql/stmt/
drop_table.rs

1use super::{Name, Statement};
2
3use toasty_core::schema::db::Table;
4
5/// A statement to drop a SQL table.
6#[derive(Debug, Clone)]
7pub struct DropTable {
8    /// Name of the table.
9    pub name: Name,
10
11    /// Whether or not to add an `IF EXISTS` clause.
12    pub if_exists: bool,
13}
14
15impl Statement {
16    /// Drops a table.
17    ///
18    /// This function _does not_ add an `IF EXISTS` clause.
19    pub fn drop_table(table: &Table) -> Self {
20        DropTable {
21            name: Name::from(&table.name[..]),
22            if_exists: false,
23        }
24        .into()
25    }
26
27    /// Drops a table if it exists.
28    ///
29    /// This function _does_ add an `IF EXISTS` clause.
30    pub fn drop_table_if_exists(table: &Table) -> Self {
31        DropTable {
32            name: Name::from(&table.name[..]),
33            if_exists: true,
34        }
35        .into()
36    }
37}
38
39impl From<DropTable> for Statement {
40    fn from(value: DropTable) -> Self {
41        Self::DropTable(value)
42    }
43}