icydb_core/db/query/fluent/load/
result.rs1use crate::{
2 db::{EntityResponse, PagedGroupedExecutionWithTrace, query::intent::QueryError},
3 traits::EntityKind,
4};
5
6#[derive(Debug)]
14pub enum LoadQueryResult<E: EntityKind> {
15 Rows(EntityResponse<E>),
16 Grouped(PagedGroupedExecutionWithTrace),
17}
18
19impl<E: EntityKind> LoadQueryResult<E> {
20 #[must_use]
22 pub fn count(&self) -> u32 {
23 match self {
24 Self::Rows(rows) => rows.count(),
25 Self::Grouped(grouped) => u32::try_from(grouped.rows().len()).unwrap_or(u32::MAX),
26 }
27 }
28
29 #[must_use]
31 pub fn is_empty(&self) -> bool {
32 self.count() == 0
33 }
34
35 pub fn into_rows(self) -> Result<EntityResponse<E>, QueryError> {
37 match self {
38 Self::Rows(rows) => Ok(rows),
39 Self::Grouped(_) => Err(QueryError::unsupported_query(
40 "grouped queries return grouped rows; call execute() and inspect the grouped result",
41 )),
42 }
43 }
44
45 pub fn into_grouped(self) -> Result<PagedGroupedExecutionWithTrace, QueryError> {
47 match self {
48 Self::Grouped(grouped) => Ok(grouped),
49 Self::Rows(_) => Err(QueryError::unsupported_query(
50 "scalar queries return entity rows; grouped results are not available",
51 )),
52 }
53 }
54}