use crate::{
db::{
PagedLoadExecutionWithTrace, QueryError,
diagnostics::ExecutionTrace,
executor::{CursorPage, PageCursor},
},
traits::EntityKind,
};
fn encode_scalar_page_cursor(cursor: Option<PageCursor>) -> Result<Option<Vec<u8>>, QueryError> {
cursor
.map(|token| {
let Some(token) = token.as_scalar() else {
return Err(QueryError::scalar_paged_emitted_grouped_continuation());
};
token.encode().map_err(|err| {
QueryError::serialize_internal(format!(
"failed to serialize continuation cursor: {err}"
))
})
})
.transpose()
}
pub(in crate::db) fn finalize_scalar_paged_execution<E: EntityKind>(
page: CursorPage<E>,
trace: Option<ExecutionTrace>,
) -> Result<PagedLoadExecutionWithTrace<E>, QueryError> {
let next_cursor = encode_scalar_page_cursor(page.next_cursor)?;
Ok(PagedLoadExecutionWithTrace::new(
page.items,
next_cursor,
trace,
))
}