toasty_sql/stmt/
drop_index.rs

1use super::{Name, Statement};
2
3use toasty_core::schema::db::Index;
4
5/// A statement to drop a SQL index.
6#[derive(Debug, Clone)]
7pub struct DropIndex {
8    /// Name of the index.
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 an index.
17    ///
18    /// This function _does not_ add an `IF EXISTS` clause.
19    pub fn drop_index(index: &Index) -> Self {
20        DropIndex {
21            name: Name::from(&index.name[..]),
22            if_exists: false,
23        }
24        .into()
25    }
26
27    /// Drops a index if it exists.
28    ///
29    /// This function _does_ add an `IF EXISTS` clause.
30    pub fn drop_index_if_exists(index: &Index) -> Self {
31        DropIndex {
32            name: Name::from(&index.name[..]),
33            if_exists: true,
34        }
35        .into()
36    }
37}
38
39impl From<DropIndex> for Statement {
40    fn from(value: DropIndex) -> Self {
41        Self::DropIndex(value)
42    }
43}