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>
impl<'a, S: ConnectionState> BulkWriter<'a, S>
Sourcepub fn send_row<T: ToSql>(&mut self, values: &[T]) -> Result<(), Error>
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.
Sourcepub fn send_row_values(&mut self, values: &[SqlValue]) -> Result<(), Error>
pub fn send_row_values(&mut self, values: &[SqlValue]) -> Result<(), Error>
Add a row of pre-converted SQL values to the buffer.
Sourcepub fn total_rows(&self) -> u64
pub fn total_rows(&self) -> u64
Get the number of rows buffered so far.
Sourcepub async fn finish(self) -> Result<BulkInsertResult, Error>
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.