use std::ops::Range;
use crate::{View, ViewColumnId, ViewColumnWalker, ViewId, Walker};
pub type ViewWalker<'a> = Walker<'a, ViewId>;
impl<'a> ViewWalker<'a> {
pub fn name(self) -> &'a str {
&self.get().name
}
pub fn definition(self) -> Option<&'a str> {
self.get().definition.as_deref()
}
pub fn namespace(self) -> Option<&'a str> {
self.schema
.namespaces
.get(self.get().namespace_id.0 as usize)
.map(|s| s.as_str())
}
pub fn columns(self) -> impl ExactSizeIterator<Item = ViewColumnWalker<'a>> {
self.columns_range().map(move |idx| self.walk(ViewColumnId(idx as u32)))
}
pub fn description(self) -> Option<&'a str> {
self.get().description.as_deref()
}
fn columns_range(self) -> Range<usize> {
super::range_for_key(&self.schema.view_columns, self.id, |(tid, _)| *tid)
}
fn get(self) -> &'a View {
&self.schema.views[self.id.0 as usize]
}
}