use alloc::string::String;
use alloc::vec::Vec;
use core::str::FromStr;
use super::*;
#[derive(Debug, Clone, Default)]
pub struct IndexesBlock {
pub span_range: SpanRange,
pub defs: Vec<IndexesDef>,
}
#[derive(Debug, Clone, Default)]
pub struct IndexesDef {
pub span_range: SpanRange,
pub cols: Vec<IndexesColumnType>,
pub settings: Option<IndexesSettings>,
}
#[derive(Debug, Clone, Default)]
pub struct IndexesSettings {
pub span_range: SpanRange,
pub attributes: Vec<Attribute>,
pub r#type: Option<IndexesType>,
pub is_unique: bool,
pub is_pk: bool,
pub note: Option<String>,
pub name: Option<String>,
}
#[derive(Debug, Clone)]
pub enum IndexesColumnType {
String(Ident),
Expr(Literal),
}
#[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)),
}
}
}