use crate::error::Result;
use crate::resolver::columns::TableScope;
#[derive(Debug, Clone, Copy)]
pub enum ColumnScope<'a> {
Unchecked,
Relations(&'a TableScope),
}
impl ColumnScope<'_> {
pub fn check_column(&self, table_ref: Option<&str>, column: &str) -> Result<()> {
match self {
Self::Unchecked => Ok(()),
Self::Relations(scope) => scope.check_name(table_ref, column),
}
}
pub fn column_qualifier(
&self,
table_ref: Option<&str>,
column: &str,
) -> Result<Option<String>> {
match self {
Self::Unchecked => Ok(table_ref.map(str::to_owned)),
Self::Relations(scope) => match table_ref {
None => scope.bare_column_qualifier(column),
Some(table) => {
scope.check_name(Some(table), column)?;
Ok(scope.qualified_column_qualifier(table))
}
},
}
}
pub fn is_row_scope(&self) -> bool {
match self {
Self::Unchecked => false,
Self::Relations(scope) => scope.is_row_scope(),
}
}
pub fn allows_cp_functions(&self) -> bool {
match self {
Self::Unchecked => false,
Self::Relations(scope) => scope.allows_cp_functions(),
}
}
}