#[cfg(feature = "diagnostics")]
use crate::db::FluentTerminalExecutionAttribution;
#[cfg(feature = "diagnostics")]
use crate::db::query::read_intent::ReadIntentKind;
use crate::{
db::{
PersistedRow,
query::{
builder::{
AvgBySlotTerminal, AvgDistinctBySlotTerminal, CountDistinctBySlotTerminal,
CountRowsTerminal, MaxIdBySlotTerminal, MaxIdTerminal, MedianIdBySlotTerminal,
MinIdBySlotTerminal, MinIdTerminal, MinMaxIdBySlotTerminal, NthIdBySlotTerminal,
SumBySlotTerminal, SumDistinctBySlotTerminal,
},
explain::{ExplainAggregateTerminalPlan, ExplainExecutionNodeDescriptor},
fluent::load::FluentLoadQuery,
intent::QueryError,
},
},
entity::EntityValue,
types::{Decimal, Id},
};
use super::driver::MinMaxByIds;
impl<E> FluentLoadQuery<'_, E>
where
E: PersistedRow,
{
pub fn count(&self) -> Result<u32, QueryError>
where
E: EntityValue,
{
self.execute_terminal(CountRowsTerminal::new())
}
pub fn count_exact(&self) -> Result<u32, QueryError>
where
E: EntityValue,
{
self.execute_exact_aggregate_terminal(CountRowsTerminal::new())
}
pub fn explain_count_exact(&self) -> Result<ExplainAggregateTerminalPlan, QueryError>
where
E: EntityValue,
{
self.explain_exact_aggregate_terminal(&CountRowsTerminal::new())
}
#[cfg(feature = "diagnostics")]
#[doc(hidden)]
pub fn count_with_attribution(
&self,
) -> Result<(u32, FluentTerminalExecutionAttribution), QueryError>
where
E: EntityValue,
{
self.execute_count_terminal_with_attribution(ReadIntentKind::BoundedRowWindow)
}
#[cfg(feature = "diagnostics")]
#[doc(hidden)]
pub fn count_exact_with_attribution(
&self,
) -> Result<(u32, FluentTerminalExecutionAttribution), QueryError>
where
E: EntityValue,
{
self.execute_count_terminal_with_attribution(ReadIntentKind::ExactAggregate)
}
pub fn min(&self) -> Result<Option<Id<E>>, QueryError>
where
E: EntityValue,
{
self.execute_terminal(MinIdTerminal::new())
}
pub fn min_id_exact(&self) -> Result<Option<Id<E>>, QueryError>
where
E: EntityValue,
{
self.execute_exact_aggregate_terminal(MinIdTerminal::new())
}
pub fn explain_min(&self) -> Result<ExplainAggregateTerminalPlan, QueryError>
where
E: EntityValue,
{
self.explain_terminal(&MinIdTerminal::new())
}
pub fn explain_min_id_exact(&self) -> Result<ExplainAggregateTerminalPlan, QueryError>
where
E: EntityValue,
{
self.explain_exact_aggregate_terminal(&MinIdTerminal::new())
}
pub fn min_by(&self, field: impl AsRef<str>) -> Result<Option<Id<E>>, QueryError>
where
E: EntityValue,
{
self.execute_slot_terminal(field, MinIdBySlotTerminal::new)
}
pub fn min_exact_by(&self, field: impl AsRef<str>) -> Result<Option<Id<E>>, QueryError>
where
E: EntityValue,
{
self.execute_exact_aggregate_by_slot_terminal(field, MinIdBySlotTerminal::new)
}
pub fn explain_min_exact_by(
&self,
field: impl AsRef<str>,
) -> Result<ExplainAggregateTerminalPlan, QueryError>
where
E: EntityValue,
{
self.explain_exact_aggregate_by_slot_terminal(field, MinIdBySlotTerminal::new)
}
pub fn max(&self) -> Result<Option<Id<E>>, QueryError>
where
E: EntityValue,
{
self.execute_terminal(MaxIdTerminal::new())
}
pub fn max_id_exact(&self) -> Result<Option<Id<E>>, QueryError>
where
E: EntityValue,
{
self.execute_exact_aggregate_terminal(MaxIdTerminal::new())
}
pub fn explain_max(&self) -> Result<ExplainAggregateTerminalPlan, QueryError>
where
E: EntityValue,
{
self.explain_terminal(&MaxIdTerminal::new())
}
pub fn explain_max_id_exact(&self) -> Result<ExplainAggregateTerminalPlan, QueryError>
where
E: EntityValue,
{
self.explain_exact_aggregate_terminal(&MaxIdTerminal::new())
}
pub fn max_by(&self, field: impl AsRef<str>) -> Result<Option<Id<E>>, QueryError>
where
E: EntityValue,
{
self.execute_slot_terminal(field, MaxIdBySlotTerminal::new)
}
pub fn max_exact_by(&self, field: impl AsRef<str>) -> Result<Option<Id<E>>, QueryError>
where
E: EntityValue,
{
self.execute_exact_aggregate_by_slot_terminal(field, MaxIdBySlotTerminal::new)
}
pub fn explain_max_exact_by(
&self,
field: impl AsRef<str>,
) -> Result<ExplainAggregateTerminalPlan, QueryError>
where
E: EntityValue,
{
self.explain_exact_aggregate_by_slot_terminal(field, MaxIdBySlotTerminal::new)
}
pub fn nth_by(&self, field: impl AsRef<str>, nth: usize) -> Result<Option<Id<E>>, QueryError>
where
E: EntityValue,
{
self.execute_slot_terminal(field, |target_slot| {
NthIdBySlotTerminal::new(target_slot, nth)
})
}
pub fn sum_by(&self, field: impl AsRef<str>) -> Result<Option<Decimal>, QueryError>
where
E: EntityValue,
{
self.execute_slot_terminal(field, SumBySlotTerminal::new)
}
pub fn sum_exact(&self, field: impl AsRef<str>) -> Result<Option<Decimal>, QueryError>
where
E: EntityValue,
{
self.execute_exact_aggregate_by_slot_terminal(field, SumBySlotTerminal::new)
}
pub fn explain_sum_exact(
&self,
field: impl AsRef<str>,
) -> Result<ExplainAggregateTerminalPlan, QueryError>
where
E: EntityValue,
{
self.explain_exact_aggregate_by_slot_terminal(field, SumBySlotTerminal::new)
}
pub fn explain_sum_by(
&self,
field: impl AsRef<str>,
) -> Result<ExplainAggregateTerminalPlan, QueryError>
where
E: EntityValue,
{
self.explain_slot_terminal(field, SumBySlotTerminal::new)
}
pub fn sum_distinct_by(&self, field: impl AsRef<str>) -> Result<Option<Decimal>, QueryError>
where
E: EntityValue,
{
self.execute_slot_terminal(field, SumDistinctBySlotTerminal::new)
}
pub fn explain_sum_distinct_by(
&self,
field: impl AsRef<str>,
) -> Result<ExplainAggregateTerminalPlan, QueryError>
where
E: EntityValue,
{
self.explain_slot_terminal(field, SumDistinctBySlotTerminal::new)
}
pub fn avg_by(&self, field: impl AsRef<str>) -> Result<Option<Decimal>, QueryError>
where
E: EntityValue,
{
self.execute_slot_terminal(field, AvgBySlotTerminal::new)
}
pub fn avg_exact(&self, field: impl AsRef<str>) -> Result<Option<Decimal>, QueryError>
where
E: EntityValue,
{
self.execute_exact_aggregate_by_slot_terminal(field, AvgBySlotTerminal::new)
}
pub fn explain_avg_by(
&self,
field: impl AsRef<str>,
) -> Result<ExplainAggregateTerminalPlan, QueryError>
where
E: EntityValue,
{
self.explain_slot_terminal(field, AvgBySlotTerminal::new)
}
pub fn explain_avg_exact(
&self,
field: impl AsRef<str>,
) -> Result<ExplainAggregateTerminalPlan, QueryError>
where
E: EntityValue,
{
self.explain_exact_aggregate_by_slot_terminal(field, AvgBySlotTerminal::new)
}
pub fn avg_distinct_by(&self, field: impl AsRef<str>) -> Result<Option<Decimal>, QueryError>
where
E: EntityValue,
{
self.execute_slot_terminal(field, AvgDistinctBySlotTerminal::new)
}
pub fn explain_avg_distinct_by(
&self,
field: impl AsRef<str>,
) -> Result<ExplainAggregateTerminalPlan, QueryError>
where
E: EntityValue,
{
self.explain_slot_terminal(field, AvgDistinctBySlotTerminal::new)
}
pub fn median_by(&self, field: impl AsRef<str>) -> Result<Option<Id<E>>, QueryError>
where
E: EntityValue,
{
self.execute_slot_terminal(field, MedianIdBySlotTerminal::new)
}
pub fn count_distinct_by(&self, field: impl AsRef<str>) -> Result<u32, QueryError>
where
E: EntityValue,
{
self.execute_slot_terminal(field, CountDistinctBySlotTerminal::new)
}
pub fn explain_count_distinct_by(
&self,
field: impl AsRef<str>,
) -> Result<ExplainExecutionNodeDescriptor, QueryError>
where
E: EntityValue,
{
self.explain_slot_terminal(field, CountDistinctBySlotTerminal::new)
}
pub fn min_max_by(&self, field: impl AsRef<str>) -> Result<MinMaxByIds<E>, QueryError>
where
E: EntityValue,
{
self.execute_slot_terminal(field, MinMaxIdBySlotTerminal::new)
}
}