Skip to main content

uqa_execution/mutation/insert/source/
binding.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Bind INSERT SELECT preparation to the source query's read generation.
8use super::InsertSelectConsumer;
9use crate::query::{consumer::QueryRowConsumer, statement::consumer::QueryConsumerFactory};
10use std::rc::Rc;
11use uqa_sql::SQLError;
12
13/// The session owner retains a live or frozen generation for the lifetime of one bound sink.
14pub trait InsertSelectBinding<S: Clone + 'static> {
15    fn bind<'a>(
16        &'a self,
17        snapshot: Option<&S>,
18        consumer: Rc<InsertSelectConsumer<S>>,
19    ) -> Result<Rc<dyn QueryRowConsumer + 'a>, SQLError>;
20}
21pub struct InsertSelectOutput<'a, S: Clone + 'static> {
22    pub binding: &'a dyn InsertSelectBinding<S>,
23    pub consumer: Rc<InsertSelectConsumer<S>>,
24}
25impl<'consumer, S: Clone + 'static> QueryConsumerFactory<'consumer, S>
26    for InsertSelectOutput<'consumer, S>
27{
28    fn bind(
29        self: Rc<Self>,
30        generation: Option<&S>,
31    ) -> Result<Rc<dyn QueryRowConsumer + 'consumer>, SQLError> {
32        self.binding.bind(generation, Rc::clone(&self.consumer))
33    }
34}