icydb_core/db/query/fluent/load/
result.rs1use crate::{
2 db::{EntityResponse, PagedGroupedExecutionWithTrace, query::intent::QueryError},
3 traits::EntityKind,
4};
5use icydb_diagnostic_code::QueryResultShapeCode;
6
7#[derive(Debug)]
15pub enum LoadQueryResult<E: EntityKind> {
16 Rows(EntityResponse<E>),
17 Grouped(PagedGroupedExecutionWithTrace),
18}
19
20impl<E: EntityKind> LoadQueryResult<E> {
21 #[must_use]
23 pub fn count(&self) -> u32 {
24 match self {
25 Self::Rows(rows) => rows.count(),
26 Self::Grouped(grouped) => u32::try_from(grouped.rows().len()).unwrap_or(u32::MAX),
27 }
28 }
29
30 #[must_use]
32 pub fn is_empty(&self) -> bool {
33 self.count() == 0
34 }
35
36 pub fn into_rows(self) -> Result<EntityResponse<E>, QueryError> {
38 match self {
39 Self::Rows(rows) => Ok(rows),
40 Self::Grouped(_) => Err(QueryError::result_shape_mismatch(
41 QueryResultShapeCode::ExpectedRows,
42 )),
43 }
44 }
45
46 pub fn into_grouped(self) -> Result<PagedGroupedExecutionWithTrace, QueryError> {
48 match self {
49 Self::Grouped(grouped) => Ok(grouped),
50 Self::Rows(_) => Err(QueryError::result_shape_mismatch(
51 QueryResultShapeCode::ExpectedGroupedRows,
52 )),
53 }
54 }
55}