pub struct MappedInserter<'conn> { /* private fields */ }Expand description
An inserter that supports SQL expression mappings.
This inserter uses a staging table to support computed columns via
INSERT…SELECT with SQL expressions. It’s created by
Inserter::with_column_mappings.
Implementations§
Source§impl<'conn> MappedInserter<'conn>
impl<'conn> MappedInserter<'conn>
Sourcepub fn add_row(&mut self, values: &[&dyn IntoValue]) -> Result<()>
pub fn add_row(&mut self, values: &[&dyn IntoValue]) -> Result<()>
Adds a row of values to the inserter.
The values should correspond to the columns in the inserter definition, not the target table.
§Errors
Forwards the error from Inserter::add_row.
Sourcepub fn execute(&mut self) -> Result<u64>
pub fn execute(&mut self) -> Result<u64>
Executes the insert with column mappings.
This method:
- Inserts all buffered rows into the staging table
- Executes INSERT…SELECT from staging to target with mappings
- Drops the staging table
Returns the number of rows inserted into the target table.
§Errors
- Returns the error from the inner
Inserter::executeif writing the staging rows fails. - Returns
Error::Clientif theINSERT ... SELECTfrom staging to the target table is rejected (e.g. a mapping expression fails to evaluate). - Returns
Error::Clientif dropping the staging table fails.
Sourcepub fn cancel(&mut self)
pub fn cancel(&mut self)
Cancels the insert and drops the staging table.
This method handles cleanup failures gracefully by logging warnings instead of returning errors. This prevents masking the original error that caused the cancellation.
§Logging
Cleanup failures are logged using the tracing crate at WARN level.
If tracing is not initialized, errors are written to stderr.
Trait Implementations§
Auto Trait Implementations§
impl<'conn> Freeze for MappedInserter<'conn>
impl<'conn> !RefUnwindSafe for MappedInserter<'conn>
impl<'conn> !Send for MappedInserter<'conn>
impl<'conn> Sync for MappedInserter<'conn>
impl<'conn> Unpin for MappedInserter<'conn>
impl<'conn> UnsafeUnpin for MappedInserter<'conn>
impl<'conn> !UnwindSafe for MappedInserter<'conn>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request