Skip to main content

MappedInserter

Struct MappedInserter 

Source
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>

Source

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.

Source

pub fn add_null(&mut self) -> Result<()>

Adds a NULL value.

§Errors

Forwards the error from Inserter::add_null.

Source

pub fn add_bool(&mut self, value: bool) -> Result<()>

Adds a boolean value.

§Errors

Forwards the error from Inserter::add_bool.

Source

pub fn add_i16(&mut self, value: i16) -> Result<()>

Adds an i16 value.

§Errors

Forwards the error from Inserter::add_i16.

Source

pub fn add_i32(&mut self, value: i32) -> Result<()>

Adds an i32 value.

§Errors

Forwards the error from Inserter::add_i32.

Source

pub fn add_i64(&mut self, value: i64) -> Result<()>

Adds an i64 value.

§Errors

Forwards the error from Inserter::add_i64.

Source

pub fn add_f32(&mut self, value: f32) -> Result<()>

Adds an f32 value.

§Errors

Forwards the error from Inserter::add_f32.

Source

pub fn add_f64(&mut self, value: f64) -> Result<()>

Adds an f64 value.

§Errors

Forwards the error from Inserter::add_f64.

Source

pub fn add_str(&mut self, value: &str) -> Result<()>

Adds a string value.

§Errors

Forwards the error from Inserter::add_str.

Source

pub fn add_bytes(&mut self, value: &[u8]) -> Result<()>

Adds a bytes value.

§Errors

Forwards the error from Inserter::add_bytes.

Source

pub fn end_row(&mut self) -> Result<()>

Ends the current row.

§Errors

Forwards the error from Inserter::end_row.

Source

pub fn execute(&mut self) -> Result<u64>

Executes the insert with column mappings.

This method:

  1. Inserts all buffered rows into the staging table
  2. Executes INSERT…SELECT from staging to target with mappings
  3. Drops the staging table

Returns the number of rows inserted into the target table.

§Errors
  • Returns the error from the inner Inserter::execute if writing the staging rows fails.
  • Returns Error::Client if the INSERT ... SELECT from staging to the target table is rejected (e.g. a mapping expression fails to evaluate).
  • Returns Error::Client if dropping the staging table fails.
Source

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§

Source§

impl<'conn> Debug for MappedInserter<'conn>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more