Skip to main content

PgPipeline

Struct PgPipeline 

Source
pub struct PgPipeline { /* private fields */ }
Expand description

High-level pipelined PostgreSQL client. Coalesces Parse+Bind+Execute+Sync into a single TCP write. Caches prepared statements to skip Parse on subsequent calls.

Implementations§

Source§

impl PgPipeline

Source

pub fn new(conn: WireConn) -> Self

Wrap a connected WireConn in a pipelining helper. Statement cache size defaults to 256 entries.

Source

pub async fn query( &mut self, sql: &str, params: &[Option<&[u8]>], param_oids: &[u32], ) -> Result<Vec<RawRow>, PgWireError>

Execute a parameterized query, returning rows as Vec<RawRow>. Uses binary format for parameters and results. On cache miss: Parse+Bind+Execute+Sync in ONE write. On cache hit: Bind+Execute+Sync in ONE write.

Source

pub async fn simple_query(&mut self, sql: &str) -> Result<(), PgWireError>

Execute a simple query (no parameters, text protocol). Used for SET LOCAL ROLE, set_config, BEGIN, COMMIT etc.

Drains all backend messages until ReadyForQuery. If the server sent an ErrorResponse, the first such error is captured and returned as Err(PgWireError::Pg(_)) once the resync completes.

Source

pub async fn simple_query_rows( &mut self, sql: &str, ) -> Result<(Vec<RawRow>, String), PgWireError>

Execute a simple query and return rows (text format). Used for introspection queries (e.g., migration status).

Source

pub async fn pipeline_with_setup( &mut self, setup_sql: &str, query_sql: &str, params: &[Option<&[u8]>], param_oids: &[u32], ) -> Result<Vec<RawRow>, PgWireError>

Execute a pipelined transaction: setup (simple) + query (parameterized) in TWO messages but coalesced into ONE TCP write.

This is the key optimization: BEGIN + SET LOCAL ROLE + set_config + parameterized query all go in one write() syscall, with the data query using the safe binary protocol.

Source

pub async fn pipeline_transaction( &mut self, setup_sql: &str, query_sql: &str, params: &[Option<&[u8]>], param_oids: &[u32], ) -> Result<Vec<RawRow>, PgWireError>

Execute a pipelined transaction with COMMIT at the end. setup_sql should contain “BEGIN; SET LOCAL ROLE …; SELECT set_config(…)” The commit is sent as a separate simple query, coalesced in the same write.

Source

pub fn clear_cache(&mut self)

Clear the statement cache (e.g., after DISCARD ALL).

Source

pub fn conn(&mut self) -> &mut WireConn

Get a mutable reference to the underlying connection.

Source

pub fn conn_ref(&self) -> &WireConn

Get a reference to the underlying connection.

Trait Implementations§

Source§

impl Debug for PgPipeline

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more