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
44
45
46
47
48
49
use std::str::FromStr;
#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct IndexesBlock {
pub defs: Vec<IndexesDef>,
}
#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct IndexesDef {
pub cols: Vec<IndexesColumnType>,
pub settings: Option<IndexesSettings>,
}
#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct IndexesSettings {
pub r#type: Option<IndexesType>,
pub is_unique: bool,
pub is_pk: bool,
pub note: Option<String>,
pub name: Option<String>,
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum IndexesColumnType {
String(String),
Expr(String),
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum IndexesType {
BTree,
Gin,
Gist,
Hash,
}
impl FromStr for IndexesType {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"btree" => Ok(Self::BTree),
"gin" => Ok(Self::Gin),
"gist" => Ok(Self::Gist),
"hash" => Ok(Self::Hash),
_ => Err(format!("'{}' type is not supported!", s)),
}
}
}