pub struct BatchWriter<'a> { /* private fields */ }Expand description
Batch writer for high-throughput operations
Supports two modes:
- Buffered mode (auto_commit=false): All ops buffered, single commit at execute()
- Streaming mode (auto_commit=true): Auto-commits every max_batch_size ops
Implementations§
Source§impl<'a> BatchWriter<'a>
impl<'a> BatchWriter<'a>
Sourcepub fn new(conn: &'a ToonConnection) -> Self
pub fn new(conn: &'a ToonConnection) -> Self
Create new batch writer
Sourcepub fn max_batch_size(self, size: usize) -> Self
pub fn max_batch_size(self, size: usize) -> Self
Set maximum batch size
In streaming mode (auto_commit=true), a commit is triggered when the batch reaches this size. Recommended values:
- 100-500: Low latency, more fsyncs
- 1000-5000: Balanced (default)
- 10000+: Maximum throughput, higher latency spikes
Sourcepub fn auto_commit(self, enabled: bool) -> Self
pub fn auto_commit(self, enabled: bool) -> Self
Enable auto-commit when batch is full
When enabled, the batch writer will automatically commit transactions
when they reach max_batch_size operations. This bounds memory usage
to O(max_batch_size) and provides predictable commit latency.
Sourcepub fn insert_slice(
self,
table: &str,
row_id: u64,
values: Vec<Option<ToonValue>>,
) -> Self
pub fn insert_slice( self, table: &str, row_id: u64, values: Vec<Option<ToonValue>>, ) -> Self
Add insert operation using slice-based values (zero-allocation path)
Values must be in schema column order. Use None for NULL values. This is the fastest insert path, matching benchmark performance.
§Example
batch.insert_slice("users", 1, vec![
Some(ToonValue::UInt(1)),
Some(ToonValue::Text("Alice".into())),
None, // NULL
])Sourcepub fn update(
self,
table: &str,
key_field: &str,
key_value: ToonValue,
updates: Vec<(&str, ToonValue)>,
) -> Self
pub fn update( self, table: &str, key_field: &str, key_value: ToonValue, updates: Vec<(&str, ToonValue)>, ) -> Self
Add update operation
Sourcepub fn delete(self, table: &str, key_field: &str, key_value: ToonValue) -> Self
pub fn delete(self, table: &str, key_field: &str, key_value: ToonValue) -> Self
Add delete operation
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Get number of pending operations (in current unflushed batch)
Sourcepub fn total_count(&self) -> usize
pub fn total_count(&self) -> usize
Get total operations processed so far (including flushed chunks)
Sourcepub fn execute(self) -> Result<BatchResult>
pub fn execute(self) -> Result<BatchResult>
Execute all pending operations
In streaming mode, this commits any remaining operations in the final partial batch. Returns cumulative results from all chunks.
Auto Trait Implementations§
impl<'a> Freeze for BatchWriter<'a>
impl<'a> !RefUnwindSafe for BatchWriter<'a>
impl<'a> Send for BatchWriter<'a>
impl<'a> Sync for BatchWriter<'a>
impl<'a> Unpin for BatchWriter<'a>
impl<'a> !UnwindSafe for BatchWriter<'a>
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more