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