use crate::{Index, IndexColumnId, IndexColumnWalker, IndexId, IndexType, TableColumnId, TableWalker, Walker};
pub type IndexWalker<'a> = Walker<'a, IndexId>;
impl<'a> IndexWalker<'a> {
pub fn column_names(self) -> impl ExactSizeIterator<Item = &'a str> {
self.columns().map(|c| c.as_column().name())
}
pub fn columns(self) -> impl ExactSizeIterator<Item = IndexColumnWalker<'a>> {
super::range_for_key(&self.schema.index_columns, self.id, |i| i.index_id)
.map(move |idx| self.walk(IndexColumnId(idx as u32)))
}
pub fn contains_column(self, column_id: TableColumnId) -> bool {
self.columns().any(|column| column.as_column().id == column_id)
}
fn get(self) -> &'a Index {
&self.schema.indexes[self.id.0 as usize]
}
pub fn index_type(self) -> IndexType {
self.get().tpe
}
pub fn is_primary_key(self) -> bool {
matches!(self.get().tpe, IndexType::PrimaryKey)
}
pub fn is_unique(self) -> bool {
matches!(self.get().tpe, IndexType::Unique)
}
pub fn name(self) -> &'a str {
&self.get().index_name
}
pub fn table(self) -> TableWalker<'a> {
self.walk(self.get().table_id)
}
}