Skip to main content

BulkWriter

Struct BulkWriter 

Source
pub struct BulkWriter<'a, S: ConnectionState> { /* private fields */ }
Expand description

Active streaming writer for bulk insert operations.

Created via crate::client::Client::bulk_insert(). Rows are buffered in memory as they are added with send_row(), then transmitted to the server when finish() is called.

The writer holds a mutable reference to the crate::Client, preventing other operations on the connection while the bulk insert is in progress.

§Example

let builder = BulkInsertBuilder::new("dbo.Users")
    .with_typed_columns(vec![
        BulkColumn::new("id", "INT", 0)?,
        BulkColumn::new("name", "NVARCHAR(100)", 1)?,
    ]);

let mut writer = client.bulk_insert(&builder).await?;
writer.send_row(&[&1i32, &"Alice"])?;
writer.send_row(&[&2i32, &"Bob"])?;
let result = writer.finish().await?;

Implementations§

Source§

impl<'a, S: ConnectionState> BulkWriter<'a, S>

Source

pub fn send_row<T: ToSql>(&mut self, values: &[T]) -> Result<(), Error>

Add a row to the bulk insert buffer.

Values are encoded immediately but not sent to the server until finish() is called. The number of values must match the number of columns defined for this bulk insert.

Source

pub fn send_row_values(&mut self, values: &[SqlValue]) -> Result<(), Error>

Add a row of pre-converted SQL values to the buffer.

Source

pub fn total_rows(&self) -> u64

Get the number of rows buffered so far.

Source

pub async fn finish(self) -> Result<BulkInsertResult, Error>

Finish the bulk insert operation and send all buffered data to the server.

Writes the DONE token, sends the accumulated row data as a BulkLoad (0x07) message, and reads the server’s response.

Auto Trait Implementations§

§

impl<'a, S> Freeze for BulkWriter<'a, S>

§

impl<'a, S> !RefUnwindSafe for BulkWriter<'a, S>

§

impl<'a, S> Send for BulkWriter<'a, S>
where S: Send,

§

impl<'a, S> Sync for BulkWriter<'a, S>
where S: Sync,

§

impl<'a, S> Unpin for BulkWriter<'a, S>

§

impl<'a, S> UnsafeUnpin for BulkWriter<'a, S>

§

impl<'a, S> !UnwindSafe for BulkWriter<'a, S>

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