use serde_json::Value as JsonValue;
use super::prepared_scalar::PreparedScalar;
use crate::MultiValuesRef;
pub(super) enum PreparedProjection<'a> {
Scalar(PreparedScalar<'a>),
BorrowedCollection(MultiValuesRef<'a>),
Collection(Vec<PreparedScalar<'a>>),
}
impl PreparedProjection<'_> {
pub(super) fn materialize(self) -> JsonValue {
match self {
Self::Scalar(value) => value.materialize(),
Self::Collection(values) => JsonValue::Array(values.into_iter().map(PreparedScalar::materialize).collect()),
Self::BorrowedCollection(MultiValuesRef::Unset(_)) => JsonValue::Null,
Self::BorrowedCollection(values) => JsonValue::Array(
(0..values.len())
.map(|index| {
let value = values.get(index).expect("index is inside the admitted collection");
PreparedScalar::Borrowed(value).materialize()
})
.collect(),
),
}
}
}