pub struct Pipeline<'a> { /* private fields */ }Expand description
Async pipeline mode for batching multiple queries.
Created by Conn::pipeline.
Implementations§
Source§impl<'a> Pipeline<'a>
impl<'a> Pipeline<'a>
Sourcepub fn exec<'s, P: ToParams>(
&mut self,
statement: &'s (impl IntoStatement + ?Sized),
params: P,
) -> Result<Ticket<'s>>
pub fn exec<'s, P: ToParams>( &mut self, statement: &'s (impl IntoStatement + ?Sized), params: P, ) -> Result<Ticket<'s>>
Queue a statement execution.
The statement can be either:
- A
&PreparedStatementreturned fromconn.prepare()orconn.prepare_batch() - A raw SQL
&strfor one-shot execution
This method only buffers the command locally - no network I/O occurs until
sync() or flush() is called.
§Example
let stmt = conn.prepare("SELECT id, name FROM users WHERE id = $1").await?;
let (r1, r2) = conn.pipeline(|p| async move {
let t1 = p.exec(&stmt, (1,))?;
let t2 = p.exec("SELECT COUNT(*) FROM users", ())?;
p.sync().await?;
let r1: Vec<(i32, String)> = p.claim_collect(t1).await?;
let r2: Option<(i64,)> = p.claim_one(t2).await?;
Ok((r1, r2))
}).await?;Sourcepub async fn flush(&mut self) -> Result<()>
pub async fn flush(&mut self) -> Result<()>
Send a FLUSH message to trigger server response.
This forces the server to send all pending responses without establishing a transaction boundary. Called automatically by claim methods when needed.
Sourcepub async fn sync(&mut self) -> Result<()>
pub async fn sync(&mut self) -> Result<()>
Send a SYNC message to establish a transaction boundary.
After calling sync, you must claim all queued operations in order. The ReadyForQuery message will be consumed automatically after claiming.
Sourcepub async fn claim_collect<T: for<'b> FromRow<'b>>(
&mut self,
ticket: Ticket<'_>,
) -> Result<Vec<T>>
pub async fn claim_collect<T: for<'b> FromRow<'b>>( &mut self, ticket: Ticket<'_>, ) -> Result<Vec<T>>
Claim and collect all rows.
Results must be claimed in the same order they were queued.
Sourcepub async fn claim_one<T: for<'b> FromRow<'b>>(
&mut self,
ticket: Ticket<'_>,
) -> Result<Option<T>>
pub async fn claim_one<T: for<'b> FromRow<'b>>( &mut self, ticket: Ticket<'_>, ) -> Result<Option<T>>
Claim and return just the first row.
Results must be claimed in the same order they were queued.
Sourcepub async fn claim_drop(&mut self, ticket: Ticket<'_>) -> Result<()>
pub async fn claim_drop(&mut self, ticket: Ticket<'_>) -> Result<()>
Claim and discard all rows.
Results must be claimed in the same order they were queued.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Returns the number of operations that have been queued but not yet claimed.
Sourcepub fn is_aborted(&self) -> bool
pub fn is_aborted(&self) -> bool
Returns true if the pipeline is in aborted state due to an error.