pub struct AsyncInserter<'conn> { /* private fields */ }Expand description
An async high-performance bulk data inserter.
AsyncInserter is the async mirror of Inserter. Both
produce identical wire output (HyperBinary COPY) and have identical
throughput characteristics; the difference is whether the network I/O is
blocking (Inserter) or async/await (AsyncInserter).
§Lifetime safety
The inserter borrows the underlying AsyncConnection for 'conn. The
borrow checker prevents the connection from being dropped or moved while
the inserter is live.
§Single-use
Like the sync Inserter, AsyncInserter is intended for one COPY session
per instance. After execute returns, the row counter is
zeroed so a stray second call returns Ok(0) rather than corrupting the
stream. To insert a second batch, construct a new AsyncInserter.
Implementations§
Source§impl<'conn> AsyncInserter<'conn>
impl<'conn> AsyncInserter<'conn>
Sourcepub fn new(
connection: &'conn AsyncConnection,
table_def: &TableDefinition,
) -> Result<Self>
pub fn new( connection: &'conn AsyncConnection, table_def: &TableDefinition, ) -> Result<Self>
Creates a new async inserter for the given table.
The underlying COPY session is started lazily on the first flush or execute, so construction is lightweight. The connection’s transport is validated eagerly — a gRPC connection returns an error immediately.
§Errors
- Returns
Error::InvalidTableDefinitioniftable_defhas zero columns. - Returns
Error::Otherifconnectionis using gRPC transport (COPY is TCP-only).
Sourcepub fn add_timestamp(&mut self, value: Timestamp) -> Result<()>
pub fn add_timestamp(&mut self, value: Timestamp) -> Result<()>
Adds a Timestamp value.
Sourcepub fn add_offset_timestamp(&mut self, value: OffsetTimestamp) -> Result<()>
pub fn add_offset_timestamp(&mut self, value: OffsetTimestamp) -> Result<()>
Adds an OffsetTimestamp value.
Sourcepub fn add_interval(&mut self, value: Interval) -> Result<()>
pub fn add_interval(&mut self, value: Interval) -> Result<()>
Adds an Interval value.
Sourcepub fn add_numeric(&mut self, value: Numeric) -> Result<()>
pub fn add_numeric(&mut self, value: Numeric) -> Result<()>
Adds a Numeric value (NUMERIC). The encoding (small vs big) is
chosen from the table definition’s column precision at this position.
§Errors
Returns an error if the column’s precision cannot be determined from the table definition (NUMERIC columns must be declared with explicit precision/scale).
Sourcepub async fn end_row(&mut self) -> Result<()>
pub async fn end_row(&mut self) -> Result<()>
Marks the end of the current row. Must be called after every full row. May trigger an automatic flush of the buffered data to the server.
§Errors
- Returns
Error::Otherif the column count for the row doesn’t match the table definition. - Returns
Error::Client/Error::Ioon transport failures during the auto-flush.
Sourcepub async fn execute(&mut self) -> Result<u64>
pub async fn execute(&mut self) -> Result<u64>
Executes the insert and commits all buffered rows.
Sends any remaining buffered data and finishes the COPY operation. Returns the number of rows inserted.
The inserter is single-use: calling execute a second time returns
Ok(0). Construct a new AsyncInserter to insert another batch.
§Errors
- Returns
Error::Otherif there’s an incomplete row (partial column). - Returns
Error::Client/Error::Ioif the COPY session or transport fails.
Trait Implementations§
Auto Trait Implementations§
impl<'conn> Freeze for AsyncInserter<'conn>
impl<'conn> !RefUnwindSafe for AsyncInserter<'conn>
impl<'conn> Send for AsyncInserter<'conn>
impl<'conn> Sync for AsyncInserter<'conn>
impl<'conn> Unpin for AsyncInserter<'conn>
impl<'conn> UnsafeUnpin for AsyncInserter<'conn>
impl<'conn> !UnwindSafe for AsyncInserter<'conn>
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request