Thanks to visit codestin.com
Credit goes to docs.rs

sqlmo/query/
create_index.rs

1use crate::{Dialect, ToSql};
2use crate::util::SqlExtension;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum IndexType {
6    BTree,
7    Hash,
8    Gist,
9    SpGist,
10    Brin,
11}
12
13impl Default for IndexType {
14    fn default() -> Self {
15        IndexType::BTree
16    }
17}
18
19/// Create index action for a table
20#[derive(Debug, Clone, PartialEq, Eq)]
21pub struct CreateIndex {
22    pub name: String,
23    pub unique: bool,
24    pub schema: Option<String>,
25    pub table: String,
26    pub columns: Vec<String>,
27    pub type_: IndexType,
28}
29
30impl ToSql for CreateIndex {
31    fn write_sql(&self, buf: &mut String, _: Dialect) {
32        buf.push_str("CREATE ");
33        if self.unique {
34            buf.push_str("UNIQUE ");
35        }
36        buf.push_quoted(&self.name);
37        buf.push_str(" ON ");
38        buf.push_table_name(&self.schema, &self.table);
39        buf.push_str(" USING ");
40        match self.type_ {
41            IndexType::BTree => buf.push_str("BTREE"),
42            IndexType::Hash => buf.push_str("HASH"),
43            IndexType::Gist => buf.push_str("GIST"),
44            IndexType::SpGist => buf.push_str("SPGIST"),
45            IndexType::Brin => buf.push_str("BRIN"),
46        }
47        buf.push_str(" (");
48        buf.push_quoted_sequence(&self.columns, ", ");
49        buf.push(')');
50    }
51}