Skip to main content

uqa_execution/mutation/entry/
context.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Name resolution before command entry and fresh execution inputs inside the transaction.
8use crate::mutation::output::MutationOutput;
9use crate::mutation::{
10    statement::context::MutationStatementContext, views::commands::SourceOutputPruning,
11};
12use uqa_sql::{
13    routines::RoutineResolution,
14    semantics::{conflict::InferenceContext, returning::ReturningAnalysisContext},
15    SQLError,
16};
17
18pub trait MutationTargetResolution {
19    fn resolve_target(&self, name: &str, bound: bool) -> Result<String, SQLError>;
20    /// Native resolvers admit the selected name; external resolvers keep their original callback.
21    fn resolve_target_with_control(
22        &self,
23        name: &str,
24        bound: bool,
25        control: &uqa_core::memory::ProductionControl<'_>,
26    ) -> Result<uqa_core::memory::Produced<String>, SQLError> {
27        control.check()?;
28        let resolved = self.resolve_target(name, bound)?;
29        Ok(control.copy_text(&resolved)?)
30    }
31}
32pub struct MutationCommandContext<'a, S: Clone + 'static> {
33    pub statement: MutationStatementContext<'a, S>,
34    pub inference: InferenceContext<'a>,
35    pub returning: ReturningAnalysisContext<'a>,
36    pub prune_source_outputs: SourceOutputPruning,
37}
38pub type MutationCommand<'a, S> =
39    Box<dyn FnOnce(&MutationCommandContext<'_, S>) -> Result<MutationOutput, SQLError> + 'a>;
40pub trait MutationCommandBoundary<S: Clone + 'static> {
41    fn with_command(&self, command: MutationCommand<'_, S>) -> Result<MutationOutput, SQLError>;
42}
43pub struct MutationEntryContext<'a, S: Clone + 'static> {
44    pub targets: &'a dyn MutationTargetResolution,
45    pub transactions: &'a dyn MutationCommandBoundary<S>,
46    pub routines: &'a dyn RoutineResolution,
47}