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
impl PgPipeline
Sourcepub fn new(conn: WireConn) -> Self
pub fn new(conn: WireConn) -> Self
Wrap a connected WireConn in a pipelining helper.
Statement cache size defaults to 256 entries.
Sourcepub async fn query(
&mut self,
sql: &str,
params: &[Option<&[u8]>],
param_oids: &[u32],
) -> Result<Vec<RawRow>, PgWireError>
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.
Sourcepub async fn simple_query(&mut self, sql: &str) -> Result<(), PgWireError>
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.
Sourcepub async fn simple_query_rows(
&mut self,
sql: &str,
) -> Result<(Vec<RawRow>, String), PgWireError>
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).
Sourcepub async fn pipeline_with_setup(
&mut self,
setup_sql: &str,
query_sql: &str,
params: &[Option<&[u8]>],
param_oids: &[u32],
) -> Result<Vec<RawRow>, PgWireError>
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.
Sourcepub async fn pipeline_transaction(
&mut self,
setup_sql: &str,
query_sql: &str,
params: &[Option<&[u8]>],
param_oids: &[u32],
) -> Result<Vec<RawRow>, PgWireError>
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.
Sourcepub fn clear_cache(&mut self)
pub fn clear_cache(&mut self)
Clear the statement cache (e.g., after DISCARD ALL).