use crate::domain::asset::error::AssetError;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum AssetKind {
Table,
View,
MaterializedView,
}
impl AssetKind {
pub fn as_str(&self) -> &'static str {
match self {
AssetKind::Table => "table",
AssetKind::View => "view",
AssetKind::MaterializedView => "materialized_view",
}
}
pub fn can_refresh(&self) -> bool {
matches!(self, AssetKind::MaterializedView)
}
}
impl std::fmt::Display for AssetKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
impl std::str::FromStr for AssetKind {
type Err = AssetError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"table" => Ok(AssetKind::Table),
"view" => Ok(AssetKind::View),
"materialized_view" | "matview" => Ok(AssetKind::MaterializedView),
other => Err(AssetError::InvalidKind(other.to_string())),
}
}
}