pub struct InsertBatcher { /* private fields */ }Expand description
INSERT Batcher
Batches INSERT statements for improved throughput.
Implementations§
Source§impl InsertBatcher
impl InsertBatcher
Sourcepub fn new(config: BatchConfig) -> Self
pub fn new(config: BatchConfig) -> Self
Create a new INSERT batcher
Sourcepub fn with_backend(self, backend: BackendConfig) -> Self
pub fn with_backend(self, backend: BackendConfig) -> Self
Attach the backend the combined INSERTs execute against. Without it the batcher seals and combines but cannot run the SQL.
Sourcepub fn add(
self: &Arc<Self>,
table: String,
columns: Vec<String>,
values: Vec<Vec<String>>,
original_sql: String,
) -> Result<BatchTicket, BatchError>
pub fn add( self: &Arc<Self>, table: String, columns: Vec<String>, values: Vec<Vec<String>>, original_sql: String, ) -> Result<BatchTicket, BatchError>
Add an INSERT to the batch.
Takes &Arc<Self> so a size-triggered flush can seal the batch
synchronously (callers observing batch_size see it drop
immediately) and then execute the combined INSERT for real on a
spawned task. Must be called from within a Tokio runtime.
Sourcepub async fn flush_batch(&self, table: &str)
pub async fn flush_batch(&self, table: &str)
Flush a single table’s batch: seal it and execute the combined INSERT against the backend.
Sourcepub fn batch_size(&self, table: &str) -> usize
pub fn batch_size(&self, table: &str) -> usize
Get the current batch size for a table
Sourcepub fn stats(&self) -> BatchStats
pub fn stats(&self) -> BatchStats
Get statistics snapshot
Sourcepub async fn shutdown(&self)
pub async fn shutdown(&self)
Shutdown the batcher: stop accepting work and flush whatever is pending (executing each combined INSERT).
Sourcepub fn start_auto_flush(self: Arc<Self>) -> JoinHandle<()>
pub fn start_auto_flush(self: Arc<Self>) -> JoinHandle<()>
Start auto-flush background task
Auto Trait Implementations§
impl !Freeze for InsertBatcher
impl !RefUnwindSafe for InsertBatcher
impl !UnwindSafe for InsertBatcher
impl Send for InsertBatcher
impl Sync for InsertBatcher
impl Unpin for InsertBatcher
impl UnsafeUnpin for InsertBatcher
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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