mod cache;
mod compile;
mod compile_cache;
mod compiled;
mod ddl;
mod delete_policy;
mod execute;
mod integrity;
mod projection;
mod result;
mod resumable_update;
mod surface;
mod update_policy;
mod write_policy;
use crate::{
db::{DbSession, QueryError},
traits::CanisterKind,
value::InputValue,
};
pub use crate::db::sql::ddl::{
SqlConstraintValidationPage, SqlConstraintValidationRevisionStatus,
SqlConstraintValidationState, SqlDdlExecutionStatus, SqlDdlMutationKind,
SqlDdlPreparationReport,
};
pub(in crate::db) use cache::SqlCompiledCommandCacheKey;
pub(in crate::db::session::sql) use cache::{
SqlCompiledCommandCacheContext, SqlCompiledCommandSurface,
};
pub(in crate::db) use compiled::{
CompiledSqlCommand, CompiledSqlInsertCommand, SqlCompiledCommandExecutionContext,
SqlCompiledSchemaFingerprint, SqlGlobalAggregateCachedPlan, SqlGlobalAggregatePlanCacheEntry,
};
pub(in crate::db) use delete_policy::{
SqlDeleteExposurePolicy, SqlDeletePolicyContext, SqlPublicBoundedDeletePlan,
SqlPublicPrimaryKeyDeletePlan, SqlValidatedDeletePlan, classify_sql_delete_statement_policy,
};
pub use integrity::SqlIntegrityError;
pub use result::SqlStatementResult;
pub(in crate::db::session) use resumable_update::validate_current_initial_mutation_job_continuation;
pub(in crate::db::session::sql) use surface::sql_statement_entity_name_from_statement;
pub use surface::{
SqlStatementDispatch, SqlStatementShellSurface, SqlStatementSurface, sql_statement_dispatch,
sql_statement_shell_surface, sql_statement_surface,
};
pub(in crate::db) use update_policy::{
SqlExactUpdatePolicy, SqlExactUpdatePolicyRejection, SqlPublicBoundedUpdatePlan,
SqlPublicPrimaryKeyUpdatePlan, SqlResumableUpdatePolicyReport, SqlTrustedExactUpdatePlan,
SqlTrustedResumableUpdatePlan, SqlUpdateExposurePolicy, SqlUpdatePolicyRejection,
SqlUpdatePolicyResult, SqlValidatedUpdatePlan, classify_sql_resumable_update_policy,
classify_sql_update_policy_for_entity, with_accepted_sql_update_policy_context,
};
#[cfg(test)]
pub(in crate::db) use write_policy::{SqlWriteExecutionBounds, SqlWriteReturningBounds};
impl<C: CanisterKind> DbSession<C> {
pub fn execute_trusted_sql_query(&self, sql: &str) -> Result<SqlStatementResult, QueryError> {
let dispatch = sql_statement_dispatch(sql)?;
self.execute_trusted_sql_query_with_entity_name(&dispatch, &[])
.map(|(result, _)| result)
}
#[doc(hidden)]
pub fn execute_trusted_sql_query_with_entity_name(
&self,
dispatch: &SqlStatementDispatch<'_>,
bindings: &[InputValue],
) -> Result<(SqlStatementResult, String), QueryError> {
let (compiled, entity_name) =
self.compile_sql_query_with_dispatch_execution_context(dispatch, bindings)?;
let result = self.execute_compiled_sql_query_context_owned(compiled)?;
Ok((result, entity_name))
}
pub fn execute_trusted_sql_mutation(
&self,
sql: &str,
) -> Result<SqlStatementResult, QueryError> {
let dispatch = sql_statement_dispatch(sql)?;
self.execute_trusted_sql_mutation_dispatch(&dispatch)
}
#[doc(hidden)]
pub fn execute_trusted_sql_mutation_dispatch(
&self,
dispatch: &SqlStatementDispatch<'_>,
) -> Result<SqlStatementResult, QueryError> {
let compiled = self.compile_sql_mutation_with_execution_context(dispatch)?;
self.execute_compiled_sql_context_owned(compiled)
}
}