use crate::{error::InternalError, traits::EntityKey, types::Id, value::Value};
pub(in crate::db) type FluentScalarTerminalIdPair<E> = Option<(Id<E>, Id<E>)>;
pub(in crate::db) enum FluentScalarTerminalOutput<E: EntityKey> {
Count(u32),
Exists(bool),
Id(Option<Id<E>>),
IdPair(FluentScalarTerminalIdPair<E>),
}
impl<E> FluentScalarTerminalOutput<E>
where
E: EntityKey,
{
fn output_kind_mismatch(message: &'static str) -> InternalError {
InternalError::query_executor_invariant(message)
}
pub(in crate::db) fn into_count(self) -> Result<u32, InternalError> {
match self {
Self::Count(value) => Ok(value),
_ => Err(Self::output_kind_mismatch(
"scalar terminal boundary COUNT output kind mismatch",
)),
}
}
pub(in crate::db) fn into_exists(self) -> Result<bool, InternalError> {
match self {
Self::Exists(value) => Ok(value),
_ => Err(Self::output_kind_mismatch(
"scalar terminal boundary EXISTS output kind mismatch",
)),
}
}
pub(in crate::db) fn into_id(self) -> Result<Option<Id<E>>, InternalError> {
match self {
Self::Id(value) => Ok(value),
_ => Err(Self::output_kind_mismatch(
"scalar terminal boundary id output kind mismatch",
)),
}
}
pub(in crate::db) fn into_id_pair(
self,
) -> Result<FluentScalarTerminalIdPair<E>, InternalError> {
match self {
Self::IdPair(value) => Ok(value),
_ => Err(Self::output_kind_mismatch(
"scalar terminal boundary id-pair output kind mismatch",
)),
}
}
}
pub(in crate::db) enum FluentProjectionTerminalOutput<E: EntityKey> {
Count(u32),
Values(Vec<Value>),
ValuesWithIds(Vec<(Id<E>, Value)>),
TerminalValue(Option<Value>),
}
impl<E> FluentProjectionTerminalOutput<E>
where
E: EntityKey,
{
fn output_kind_mismatch(message: &'static str) -> InternalError {
InternalError::query_executor_invariant(message)
}
pub(in crate::db) fn into_values(self) -> Result<Vec<Value>, InternalError> {
match self {
Self::Values(values) => Ok(values),
_ => Err(Self::output_kind_mismatch(
"scalar projection boundary values output kind mismatch",
)),
}
}
pub(in crate::db) fn into_count(self) -> Result<u32, InternalError> {
match self {
Self::Count(value) => Ok(value),
_ => Err(Self::output_kind_mismatch(
"scalar projection boundary count output kind mismatch",
)),
}
}
pub(in crate::db) fn into_values_with_ids(self) -> Result<Vec<(Id<E>, Value)>, InternalError> {
match self {
Self::ValuesWithIds(values) => Ok(values),
_ => Err(Self::output_kind_mismatch(
"scalar projection boundary values-with-ids output kind mismatch",
)),
}
}
pub(in crate::db) fn into_terminal_value(self) -> Result<Option<Value>, InternalError> {
match self {
Self::TerminalValue(value) => Ok(value),
_ => Err(Self::output_kind_mismatch(
"scalar projection boundary terminal-value output kind mismatch",
)),
}
}
}