Pipeline

Struct Pipeline 

Source
pub struct Pipeline<'a> { /* private fields */ }
Expand description

Pipeline mode for batching multiple queries.

Created by Conn::pipeline.

Implementations§

Source§

impl<'a> Pipeline<'a>

Source

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 &PreparedStatement returned from conn.prepare() or conn.prepare_batch()
  • A raw SQL &str for 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")?;

let (r1, r2) = conn.pipeline(|p| {
    let t1 = p.exec(&stmt, (1,))?;
    let t2 = p.exec("SELECT COUNT(*) FROM users", ())?;
    p.sync()?;

    let r1: Vec<(i32, String)> = p.claim_collect(t1)?;
    let r2: Option<(i64,)> = p.claim_one(t2)?;
    Ok((r1, r2))
})?;
Source

pub 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.

Source

pub 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.

Source

pub 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.

Source

pub 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.

Source

pub fn claim_drop(&mut self, ticket: Ticket<'_>) -> Result<()>

Claim and discard all rows.

Results must be claimed in the same order they were queued.

Source

pub fn pending_count(&self) -> usize

Returns the number of operations that have been queued but not yet claimed.

Source

pub fn is_aborted(&self) -> bool

Returns true if the pipeline is in aborted state due to an error.

Auto Trait Implementations§

§

impl<'a> Freeze for Pipeline<'a>

§

impl<'a> !RefUnwindSafe for Pipeline<'a>

§

impl<'a> Send for Pipeline<'a>

§

impl<'a> !Sync for Pipeline<'a>

§

impl<'a> Unpin for Pipeline<'a>

§

impl<'a> !UnwindSafe for Pipeline<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V