mod table_default;
mod view_default;
use prisma_value::PrismaValue;
pub use table_default::TableDefaultValueWalker;
pub use view_default::ViewDefaultValueWalker;
use either::Either;
use crate::{DefaultKind, DefaultValue, TableDefaultValueId, ViewDefaultValueId, Walker};
pub type DefaultValueWalker<'a> = Walker<'a, Either<TableDefaultValueId, ViewDefaultValueId>>;
impl<'a> DefaultValueWalker<'a> {
pub fn refine(self) -> Either<TableDefaultValueWalker<'a>, ViewDefaultValueWalker<'a>> {
match self.id {
Either::Left(table_default) => Either::Left(self.walk(table_default)),
Either::Right(view_default) => Either::Right(self.walk(view_default)),
}
}
pub fn as_value(self) -> Option<&'a PrismaValue> {
match self.kind() {
DefaultKind::Value(ref v) => Some(v),
_ => None,
}
}
pub fn as_sequence(self) -> Option<&'a str> {
match self.kind() {
DefaultKind::Sequence(name) => Some(name),
_ => None,
}
}
pub fn is_value(&self) -> bool {
matches!(self.kind(), DefaultKind::Value(_))
}
pub fn is_now(&self) -> bool {
matches!(self.kind(), DefaultKind::Now)
}
pub fn is_sequence(&self) -> bool {
matches!(self.kind(), DefaultKind::Sequence(_))
}
pub fn is_db_generated(&self) -> bool {
matches!(self.kind(), DefaultKind::DbGenerated(_))
}
pub fn kind(self) -> &'a DefaultKind {
&self.value().kind
}
pub fn constraint_name(self) -> Option<&'a str> {
self.value().constraint_name.as_deref()
}
pub fn value(self) -> &'a DefaultValue {
match self.id {
Either::Left(id) => &self.schema.table_default_values[id.0 as usize].1,
Either::Right(id) => &self.schema.view_default_values[id.0 as usize].1,
}
}
}