pub struct BatchingSqlxClient /* private fields */ A SQLx client that automatically batches INSERT statements and routes them through BulkInserter<GenericRecord> for high-performance shard-aware ingestion.
This client intercepts INSERT statements executed in a loop, accumulates them, and flushes them through the high-performance BulkInserter when the batch size is reached. Non-INSERT statements are executed immediately via SQLx.
Features
- Auto-batching: INSERT statements are automatically accumulated
- Shard-aware routing: Uses
BulkInserter<GenericRecord>for multi-head ingest - Mixed statements: SELECT, CREATE, etc. work normally alongside INSERTs
- Performance: Achieves high throughput for bulk INSERT operations
Example
Implementations
Create a new batching SQLx client.
pool- SQLx PostgreSQL connection pool, for statements other than INSERTkinetica- The Kinetica HTTP API client INSERT batches are flushed throughbatch_size- Number of records to accumulate before flushing (recommended: 10000-50000)num_workers- Number of parallel workers for BulkInserter (recommended: 4-16)
pub fn with_options( pool: KineticaPool, kinetica: Arc<Kinetica>, batch_size: usize, num_workers: usize, options: BulkInserterOptions, ) -> Self
Create a batching client with custom options (e.g., upsert mode).
pub fn with_hints( pool: KineticaPool, kinetica: Arc<Kinetica>, batch_size: usize, num_workers: usize, hints: SqlHints, ) -> Self
Create a batching client with SQL hints.
pub fn with_options_and_hints( pool: KineticaPool, kinetica: Arc<Kinetica>, batch_size: usize, num_workers: usize, options: BulkInserterOptions, hints: SqlHints, ) -> Self
Create a batching client with both BulkInserter options and SQL hints.
Set SQL hints for the client.
Note: For INSERT statements, hints like update_on_existing_pk are automatically applied through the BulkInserter options.
Execute a SQL statement.
- INSERT statements are accumulated and batched automatically
- Other statements (SELECT, CREATE, etc.) are executed immediately via SQLx
When the batch size is reached, records are automatically flushed through BulkInserter<GenericRecord> with shard-aware routing.
Flush all pending records for all tables.
pub async fn close(self) -> Result<BatchingSqlxStats, BatchingSqlxError>
Flush all pending records and return final statistics.
This should be called when you’re done inserting to ensure all records are flushed.
pub fn pending_count(&self) -> usize
Get the number of pending (unflushed) records across all tables.
pub fn stats(&self) -> BatchingSqlxStats
Get current statistics without closing.
pub fn pool(&self) -> &KineticaPool
Get a reference to the SQLx pool for direct queries.