#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Index {
pub(crate) id: u32,
pub(crate) name: String,
pub(crate) kind: IndexKind,
pub(crate) unique: bool,
pub(crate) columns: Vec<IndexColumn>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum IndexKind {
PrimaryKey,
ForeignKey,
Secondary,
Text,
Other,
}
impl IndexKind {
pub(crate) fn from_catalog(category: u64) -> Self {
match category {
1 => Self::PrimaryKey,
2 => Self::ForeignKey,
3 => Self::Secondary,
4 => Self::Text,
_ => Self::Other,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct IndexColumn {
pub(crate) position: usize,
pub(crate) order: IndexOrder,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum IndexOrder {
Ascending,
Descending,
}
impl Index {
#[must_use]
pub fn id(&self) -> u32 {
self.id
}
#[must_use]
pub fn name(&self) -> &str {
&self.name
}
#[must_use]
pub fn kind(&self) -> IndexKind {
self.kind
}
#[must_use]
pub fn is_unique(&self) -> bool {
self.unique
}
#[must_use]
pub fn columns(&self) -> &[IndexColumn] {
&self.columns
}
}
impl IndexColumn {
#[must_use]
pub fn position(self) -> usize {
self.position
}
#[must_use]
pub fn order(self) -> IndexOrder {
self.order
}
}