mod aggregate;
mod driver;
mod output;
mod projection;
mod read_intent;
mod support;
#[cfg(feature = "diagnostics")]
use crate::db::QueryExecutionAttribution;
use crate::{
db::{
DbSession, PersistedRow,
query::{
api::ResponseCardinalityExt,
builder::{FirstIdTerminal, LastIdTerminal},
explain::{ExplainAggregateTerminalPlan, ExplainExecutionNodeDescriptor},
fluent::load::{FluentLoadQuery, LoadQueryResult},
intent::QueryError,
},
response::EntityResponse,
},
traits::EntityValue,
types::Id,
};
impl<E> FluentLoadQuery<'_, E>
where
E: PersistedRow,
{
pub fn execute(&self) -> Result<LoadQueryResult<E>, QueryError>
where
E: EntityValue,
{
self.with_admitted_non_paged(DbSession::execute_query_result)
}
#[cfg(feature = "diagnostics")]
#[doc(hidden)]
pub fn execute_with_attribution(
&self,
) -> Result<(LoadQueryResult<E>, QueryExecutionAttribution), QueryError>
where
E: EntityValue,
{
self.with_admitted_non_paged(DbSession::execute_query_result_with_attribution)
}
pub fn execute_rows(&self) -> Result<EntityResponse<E>, QueryError>
where
E: EntityValue,
{
self.with_admitted_non_paged(DbSession::execute_scalar_query_rows)
}
pub fn explain_execution(&self) -> Result<ExplainExecutionNodeDescriptor, QueryError>
where
E: EntityValue,
{
self.explain_execution_descriptor()
}
pub fn explain_execution_text(&self) -> Result<String, QueryError>
where
E: EntityValue,
{
self.render_execution_descriptor(|descriptor| descriptor.render_text_tree())
}
pub fn explain_execution_json(&self) -> Result<String, QueryError>
where
E: EntityValue,
{
self.with_non_paged(DbSession::explain_query_execution_json_with_visible_indexes)
}
pub fn explain_execution_verbose(&self) -> Result<String, QueryError>
where
E: EntityValue,
{
self.with_non_paged(DbSession::explain_query_execution_verbose_with_visible_indexes)
}
pub fn bytes(&self) -> Result<u64, QueryError>
where
E: EntityValue,
{
self.with_admitted_non_paged(DbSession::execute_fluent_bytes)
}
pub fn bytes_by(&self, field: impl AsRef<str>) -> Result<u64, QueryError>
where
E: EntityValue,
{
self.with_admitted_non_paged_slot(field, |session, query, target_slot| {
session.execute_fluent_bytes_by_slot(query, target_slot)
})
}
pub fn explain_bytes_by(
&self,
field: impl AsRef<str>,
) -> Result<ExplainExecutionNodeDescriptor, QueryError>
where
E: EntityValue,
{
self.with_non_paged_slot(field, |session, query, target_slot| {
session.explain_query_bytes_by_with_visible_indexes(query, target_slot.field())
})
}
pub fn first(&self) -> Result<Option<Id<E>>, QueryError>
where
E: EntityValue,
{
self.execute_terminal(FirstIdTerminal::new())
}
pub fn explain_first(&self) -> Result<ExplainAggregateTerminalPlan, QueryError>
where
E: EntityValue,
{
self.explain_terminal(&FirstIdTerminal::new())
}
pub fn last(&self) -> Result<Option<Id<E>>, QueryError>
where
E: EntityValue,
{
self.execute_terminal(LastIdTerminal::new())
}
pub fn explain_last(&self) -> Result<ExplainAggregateTerminalPlan, QueryError>
where
E: EntityValue,
{
self.explain_terminal(&LastIdTerminal::new())
}
pub fn require_one(&self) -> Result<(), QueryError>
where
E: EntityValue,
{
self.execute_rows()?.require_one()?;
Ok(())
}
pub fn require_some(&self) -> Result<(), QueryError>
where
E: EntityValue,
{
self.execute_rows()?.require_some()?;
Ok(())
}
}