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