pub struct PgPipeline { /* private fields */ }Expand description
A batched-dispatch pipeline for PostgreSQL.
Create via PgConnection::pipeline, queue queries with
add_execute and add_query,
then send all at once with finish.
See the module documentation for design limitations.
Implementations§
Source§impl PgPipeline
impl PgPipeline
Sourcepub fn add_execute(&mut self, sql: &str, params: &[&dyn ToSqlValue])
pub fn add_execute(&mut self, sql: &str, params: &[&dyn ToSqlValue])
Queue a write (DML/DDL) statement to be executed when finish is called.
params may be empty for parameter-free SQL.
Sourcepub fn add_query(&mut self, sql: &str, params: &[&dyn ToSqlValue])
pub fn add_query(&mut self, sql: &str, params: &[&dyn ToSqlValue])
Queue a read (SELECT) statement to be executed when finish is called.
params may be empty for parameter-free SQL.
Sourcepub async fn finish(self) -> Result<PipelineResult, PgError>
pub async fn finish(self) -> Result<PipelineResult, PgError>
Send all queued queries in a single pass and return collected results.
Internally this does two sequential passes under the connection lock:
-
Prepare pass — compile every distinct SQL string once. All
PREPAREmessages are flushed to the server before anyEXECUTEmessages, allowing the server to start planning while the client sends the remaining requests (wire-level pipelining). -
Execute pass — run each query in enqueue order, collecting rows-affected counts and row sets respectively.
Returns a PipelineResult whose executes and queries vecs are
in the same order as the corresponding add_* calls.
§Errors
Returns PgError on any preparation, execution, or type-conversion
failure. On error, results collected up to that point are discarded.