pub struct PgConnection { /* private fields */ }Expand description
A raw PostgreSQL connection.
Implementations§
Source§impl PgConnection
impl PgConnection
Source§impl PgConnection
impl PgConnection
Sourcepub async fn connect(
host: &str,
port: u16,
user: &str,
database: &str,
) -> PgResult<Self>
pub async fn connect( host: &str, port: u16, user: &str, database: &str, ) -> PgResult<Self>
Connect to PostgreSQL server without authentication (trust mode).
§Arguments
host— PostgreSQL server hostname or IP.port— TCP port (typically 5432).user— PostgreSQL role name.database— Target database name.
Sourcepub async fn connect_with_password(
host: &str,
port: u16,
user: &str,
database: &str,
password: Option<&str>,
) -> PgResult<Self>
pub async fn connect_with_password( host: &str, port: u16, user: &str, database: &str, password: Option<&str>, ) -> PgResult<Self>
Connect to PostgreSQL server with optional password authentication. Includes a default 10-second timeout covering TCP connect + handshake.
Startup requests protocol 3.2 by default and performs a one-shot retry with protocol 3.0 only when startup fails due to explicit protocol-version rejection from the server.
Sourcepub async fn connect_with_options(
host: &str,
port: u16,
user: &str,
database: &str,
password: Option<&str>,
options: ConnectOptions,
) -> PgResult<Self>
pub async fn connect_with_options( host: &str, port: u16, user: &str, database: &str, password: Option<&str>, options: ConnectOptions, ) -> PgResult<Self>
Connect to PostgreSQL with explicit enterprise options.
Negotiation preface order follows libpq:
- If gss_enc_mode != Disable → try GSSENCRequest on fresh TCP
- If GSSENC rejected/unavailable and tls_mode != Disable → try SSLRequest
- If both rejected/unavailable → plain StartupMessage
The StartupMessage protocol version behavior is the same as
connect_with_password: request protocol 3.2 first, then retry once
with 3.0 only on explicit protocol-version rejection.
Sourcepub async fn connect_with_password_and_auth(
host: &str,
port: u16,
user: &str,
database: &str,
password: Option<&str>,
auth_settings: AuthSettings,
) -> PgResult<Self>
pub async fn connect_with_password_and_auth( host: &str, port: u16, user: &str, database: &str, password: Option<&str>, auth_settings: AuthSettings, ) -> PgResult<Self>
Connect to PostgreSQL server with optional password authentication and auth policy.
Sourcepub async fn connect_tls(
host: &str,
port: u16,
user: &str,
database: &str,
password: Option<&str>,
) -> PgResult<Self>
pub async fn connect_tls( host: &str, port: u16, user: &str, database: &str, password: Option<&str>, ) -> PgResult<Self>
Connect to PostgreSQL server with TLS encryption. Includes a default 10-second timeout covering TCP connect + TLS + handshake.
Sourcepub async fn connect_tls_with_auth(
host: &str,
port: u16,
user: &str,
database: &str,
password: Option<&str>,
auth_settings: AuthSettings,
ca_cert_pem: Option<&[u8]>,
) -> PgResult<Self>
pub async fn connect_tls_with_auth( host: &str, port: u16, user: &str, database: &str, password: Option<&str>, auth_settings: AuthSettings, ca_cert_pem: Option<&[u8]>, ) -> PgResult<Self>
Connect to PostgreSQL over TLS with explicit auth policy and optional custom CA bundle.
Sourcepub async fn connect_mtls(
host: &str,
port: u16,
user: &str,
database: &str,
config: TlsConfig,
) -> PgResult<Self>
pub async fn connect_mtls( host: &str, port: u16, user: &str, database: &str, config: TlsConfig, ) -> PgResult<Self>
Connect with mutual TLS (client certificate authentication).
§Arguments
host- PostgreSQL server hostnameport- PostgreSQL server portuser- Database userdatabase- Database nameconfig- TLS configuration with client cert/key
§Example
let config = TlsConfig {
client_cert_pem: include_bytes!("client.crt").to_vec(),
client_key_pem: include_bytes!("client.key").to_vec(),
ca_cert_pem: Some(include_bytes!("ca.crt").to_vec()),
};
let conn = PgConnection::connect_mtls("localhost", 5432, "user", "db", config).await?;Source§impl PgConnection
impl PgConnection
Source§impl PgConnection
impl PgConnection
Sourcepub fn requested_protocol_minor(&self) -> u16
pub fn requested_protocol_minor(&self) -> u16
Startup protocol minor requested by this connection.
Sourcepub fn negotiated_protocol_minor(&self) -> u16
pub fn negotiated_protocol_minor(&self) -> u16
Startup protocol minor negotiated with the server.
Sourcepub fn transport_backend(&self) -> &'static str
pub fn transport_backend(&self) -> &'static str
Active transport backend label for this connection.
Returns "tokio" or "io_uring" for plain TCP connections,
and "tokio" for TLS/Unix/GSSENC paths.
Source§impl PgConnection
impl PgConnection
Sourcepub async fn copy_in_raw(
&mut self,
table: &str,
columns: &[String],
data: &[u8],
) -> PgResult<u64>
pub async fn copy_in_raw( &mut self, table: &str, columns: &[String], data: &[u8], ) -> PgResult<u64>
Fastest bulk insert using COPY protocol with pre-encoded data. Accepts raw COPY text format bytes, no encoding needed. Use when caller has already encoded rows to COPY format.
§Format
Data should be tab-separated rows with newlines:
1\thello\t3.14\n2\tworld\t2.71\n
Sourcepub async fn copy_export_stream_raw<F, Fut>(
&mut self,
cmd: &Qail,
on_chunk: F,
) -> PgResult<()>
pub async fn copy_export_stream_raw<F, Fut>( &mut self, cmd: &Qail, on_chunk: F, ) -> PgResult<()>
Stream COPY TO STDOUT chunks using an AST-native Qail::Export command.
Chunks are forwarded as they arrive from PostgreSQL, so memory usage stays bounded by network frame size and callback processing.
Sourcepub async fn copy_export_stream_rows<F>(
&mut self,
cmd: &Qail,
on_row: F,
) -> PgResult<()>
pub async fn copy_export_stream_rows<F>( &mut self, cmd: &Qail, on_row: F, ) -> PgResult<()>
Stream COPY TO STDOUT rows using an AST-native Qail::Export command.
Parses PostgreSQL COPY text lines into Vec<String> rows and invokes
on_row for each row without buffering the full result.
Source§impl PgConnection
impl PgConnection
Sourcepub async fn send(&mut self, msg: FrontendMessage) -> PgResult<()>
pub async fn send(&mut self, msg: FrontendMessage) -> PgResult<()>
Send a frontend message.
Sourcepub async fn recv(&mut self) -> PgResult<BackendMessage>
pub async fn recv(&mut self) -> PgResult<BackendMessage>
Loops until a complete message is available. Automatically buffers NotificationResponse messages for LISTEN/NOTIFY.
Sourcepub async fn send_bytes(&mut self, bytes: &[u8]) -> PgResult<()>
pub async fn send_bytes(&mut self, bytes: &[u8]) -> PgResult<()>
Send raw bytes to the stream. Includes flush for TLS safety — TLS buffers internally and needs flush to push encrypted data to the underlying TCP socket.
Sourcepub fn buffer_bytes(&mut self, bytes: &[u8])
pub fn buffer_bytes(&mut self, bytes: &[u8])
Buffer bytes for later flush (NO SYSCALL). Use flush_write_buf() to send all buffered data.
Sourcepub async fn flush_write_buf(&mut self) -> PgResult<()>
pub async fn flush_write_buf(&mut self) -> PgResult<()>
Flush the write buffer to the stream (single write_all + flush). The flush is critical for TLS connections.
Source§impl PgConnection
impl PgConnection
Sourcepub async fn listen(&mut self, channel: &str) -> PgResult<()>
pub async fn listen(&mut self, channel: &str) -> PgResult<()>
Subscribe to a notification channel.
conn.listen("price_calendar_changed").await?;Sourcepub async fn unlisten(&mut self, channel: &str) -> PgResult<()>
pub async fn unlisten(&mut self, channel: &str) -> PgResult<()>
Unsubscribe from a notification channel.
Sourcepub async fn unlisten_all(&mut self) -> PgResult<()>
pub async fn unlisten_all(&mut self) -> PgResult<()>
Unsubscribe from all notification channels.
Sourcepub fn poll_notifications(&mut self) -> Vec<Notification>
pub fn poll_notifications(&mut self) -> Vec<Notification>
Drain all buffered notifications without blocking.
Notifications arrive asynchronously from PostgreSQL and are buffered
whenever recv() encounters a NotificationResponse. This method
returns all currently buffered notifications.
Sourcepub async fn recv_notification(&mut self) -> PgResult<Notification>
pub async fn recv_notification(&mut self) -> PgResult<Notification>
Wait for the next notification, blocking until one arrives.
Unlike recv(), this does NOT use the 30-second Slowloris timeout
guard. LISTEN connections idle for long periods — that’s normal,
not a DoS attack.
Useful for a dedicated LISTEN connection in a background task.
Source§impl PgConnection
impl PgConnection
Sourcepub async fn query_pipeline(
&mut self,
queries: &[(&str, &[Option<Vec<u8>>])],
) -> PgResult<Vec<Vec<Vec<Option<Vec<u8>>>>>>
pub async fn query_pipeline( &mut self, queries: &[(&str, &[Option<Vec<u8>>])], ) -> PgResult<Vec<Vec<Vec<Option<Vec<u8>>>>>>
Execute multiple SQL queries in a single network round-trip (PIPELINING).
Sourcepub async fn query_pipeline_count(
&mut self,
queries: &[(&str, &[Option<Vec<u8>>])],
) -> PgResult<usize>
pub async fn query_pipeline_count( &mut self, queries: &[(&str, &[Option<Vec<u8>>])], ) -> PgResult<usize>
Execute multiple uncached SQL queries in one round-trip and drain completion without materializing rows.
Sourcepub async fn query_pipeline_visit_bytes_rows<F>(
&mut self,
queries: &[(&str, &[Option<Vec<u8>>])],
on_row: F,
) -> PgResult<usize>
pub async fn query_pipeline_visit_bytes_rows<F>( &mut self, queries: &[(&str, &[Option<Vec<u8>>])], on_row: F, ) -> PgResult<usize>
Execute multiple uncached SQL queries in one round-trip and stream result rows through a zero-copy visitor.
Sourcepub async fn query_pipeline_visit_first_column_bytes<F>(
&mut self,
queries: &[(&str, &[Option<Vec<u8>>])],
on_value: F,
) -> PgResult<usize>
pub async fn query_pipeline_visit_first_column_bytes<F>( &mut self, queries: &[(&str, &[Option<Vec<u8>>])], on_value: F, ) -> PgResult<usize>
Execute multiple uncached SQL queries in one round-trip and stream only the first column of each row.
Sourcepub async fn pipeline_execute_rows_ast(
&mut self,
cmds: &[Qail],
) -> PgResult<Vec<Vec<Vec<Option<Vec<u8>>>>>>
pub async fn pipeline_execute_rows_ast( &mut self, cmds: &[Qail], ) -> PgResult<Vec<Vec<Vec<Option<Vec<u8>>>>>>
Execute multiple Qail ASTs in a single network round-trip.
Sourcepub async fn pipeline_execute_count_ast_oneshot(
&mut self,
cmds: &[Qail],
) -> PgResult<usize>
pub async fn pipeline_execute_count_ast_oneshot( &mut self, cmds: &[Qail], ) -> PgResult<usize>
FAST AST pipeline - returns only query count, no result parsing.
Sourcepub async fn pipeline_execute_count_ast_with_mode(
&mut self,
cmds: &[Qail],
mode: AstPipelineMode,
) -> PgResult<usize>
pub async fn pipeline_execute_count_ast_with_mode( &mut self, cmds: &[Qail], mode: AstPipelineMode, ) -> PgResult<usize>
Execute AST pipeline with explicit strategy mode.
Auto uses a lightweight batch-size heuristic:
< 8queries: one-shot path (pipeline_execute_count_ast_oneshot)>= 8queries: cached path (pipeline_execute_count_ast_cached)
Sourcepub async fn pipeline_execute_count_wire(
&mut self,
wire_bytes: &[u8],
expected_queries: usize,
) -> PgResult<usize>
pub async fn pipeline_execute_count_wire( &mut self, wire_bytes: &[u8], expected_queries: usize, ) -> PgResult<usize>
FASTEST extended query pipeline - takes pre-encoded wire bytes.
Sourcepub async fn pipeline_execute_count_simple_ast(
&mut self,
cmds: &[Qail],
) -> PgResult<usize>
pub async fn pipeline_execute_count_simple_ast( &mut self, cmds: &[Qail], ) -> PgResult<usize>
Simple query protocol pipeline - uses ‘Q’ message.
Sourcepub async fn pipeline_execute_count_simple_wire(
&mut self,
wire_bytes: &[u8],
expected_queries: usize,
) -> PgResult<usize>
pub async fn pipeline_execute_count_simple_wire( &mut self, wire_bytes: &[u8], expected_queries: usize, ) -> PgResult<usize>
FASTEST simple query pipeline - takes pre-encoded bytes.
Sourcepub async fn pipeline_execute_count_ast_cached(
&mut self,
cmds: &[Qail],
) -> PgResult<usize>
pub async fn pipeline_execute_count_ast_cached( &mut self, cmds: &[Qail], ) -> PgResult<usize>
CACHED PREPARED STATEMENT pipeline - Parse once, Bind+Execute many.
- Generate SQL template with $1, $2, etc. placeholders
- Parse template ONCE (cached in PostgreSQL)
- Send Bind+Execute for each instance (params differ per query)
Sourcepub async fn pipeline_execute_prepared_count(
&mut self,
stmt: &PreparedStatement,
params_batch: &[Vec<Option<Vec<u8>>>],
) -> PgResult<usize>
pub async fn pipeline_execute_prepared_count( &mut self, stmt: &PreparedStatement, params_batch: &[Vec<Option<Vec<u8>>>], ) -> PgResult<usize>
ZERO-LOOKUP prepared statement pipeline.
- Hash computation per query
- HashMap lookup per query
- String allocation for stmt_name
§Example
// Prepare once (outside timing loop):
let stmt = PreparedStatement::from_sql("SELECT id, name FROM harbors LIMIT $1");
let params_batch: Vec<Vec<Option<Vec<u8>>>> = (1..=1000)
.map(|i| vec![Some(i.to_string().into_bytes())])
.collect();
// Execute many (no hash, no lookup!):
conn.pipeline_execute_prepared_count(&stmt, ¶ms_batch).await?;Sourcepub async fn prepare(&mut self, sql: &str) -> PgResult<PreparedStatement>
pub async fn prepare(&mut self, sql: &str) -> PgResult<PreparedStatement>
Prepare a statement and return a handle for fast execution. PreparedStatement handle for use with pipeline_execute_prepared_count.
Sourcepub async fn pipeline_execute_prepared_rows(
&mut self,
stmt: &PreparedStatement,
params_batch: &[Vec<Option<Vec<u8>>>],
) -> PgResult<Vec<Vec<Vec<Option<Vec<u8>>>>>>
pub async fn pipeline_execute_prepared_rows( &mut self, stmt: &PreparedStatement, params_batch: &[Vec<Option<Vec<u8>>>], ) -> PgResult<Vec<Vec<Vec<Option<Vec<u8>>>>>>
Execute a prepared statement pipeline and return all row data.
Sourcepub async fn pipeline_execute_prepared_rows_bytes(
&mut self,
stmt: &PreparedStatement,
params_batch: &[Vec<Option<Vec<u8>>>],
) -> PgResult<Vec<Vec<Vec<Option<Bytes>>>>>
pub async fn pipeline_execute_prepared_rows_bytes( &mut self, stmt: &PreparedStatement, params_batch: &[Vec<Option<Vec<u8>>>], ) -> PgResult<Vec<Vec<Vec<Option<Bytes>>>>>
ZERO-COPY pipeline execution with Bytes for column data.
Sourcepub async fn pipeline_execute_prepared_visit_rows<F>(
&mut self,
stmt: &PreparedStatement,
params_batch: &[Vec<Option<Vec<u8>>>],
on_row: F,
) -> PgResult<usize>
pub async fn pipeline_execute_prepared_visit_rows<F>( &mut self, stmt: &PreparedStatement, params_batch: &[Vec<Option<Vec<u8>>>], on_row: F, ) -> PgResult<usize>
Pipeline execution with row visitor.
Rows are streamed to on_row as owned column buffers, avoiding
materializing the full result set.
Sourcepub async fn pipeline_execute_prepared_visit_bytes_rows<F>(
&mut self,
stmt: &PreparedStatement,
params_batch: &[Vec<Option<Vec<u8>>>],
on_row: F,
) -> PgResult<usize>
pub async fn pipeline_execute_prepared_visit_bytes_rows<F>( &mut self, stmt: &PreparedStatement, params_batch: &[Vec<Option<Vec<u8>>>], on_row: F, ) -> PgResult<usize>
Pipeline execution with zero-copy row visitor.
Rows are backed by one shared payload buffer plus column offsets, avoiding per-cell byte copies during receive.
Sourcepub async fn pipeline_execute_prepared_visit_first_column_bytes<F>(
&mut self,
stmt: &PreparedStatement,
params_batch: &[Vec<Option<Vec<u8>>>],
on_value: F,
) -> PgResult<usize>
pub async fn pipeline_execute_prepared_visit_first_column_bytes<F>( &mut self, stmt: &PreparedStatement, params_batch: &[Vec<Option<Vec<u8>>>], on_value: F, ) -> PgResult<usize>
Pipeline execution with first-column visitor for scalar result sets.
Sourcepub async fn pipeline_execute_prepared_visit_first_four_columns_bytes<F>(
&mut self,
stmt: &PreparedStatement,
params_batch: &[Vec<Option<Vec<u8>>>],
on_row: F,
) -> PgResult<usize>
pub async fn pipeline_execute_prepared_visit_first_four_columns_bytes<F>( &mut self, stmt: &PreparedStatement, params_batch: &[Vec<Option<Vec<u8>>>], on_row: F, ) -> PgResult<usize>
Pipeline execution with fixed 4-column visitor for scalar result sets.
Source§impl PgConnection
impl PgConnection
Sourcepub async fn query_count(
&mut self,
sql: &str,
params: &[Option<Vec<u8>>],
) -> PgResult<()>
pub async fn query_count( &mut self, sql: &str, params: &[Option<Vec<u8>>], ) -> PgResult<()>
Execute an uncached query and drain completion without materializing rows.
Sourcepub async fn query_count_with_param_types(
&mut self,
sql: &str,
param_types: &[u32],
params: &[Option<Vec<u8>>],
) -> PgResult<()>
pub async fn query_count_with_param_types( &mut self, sql: &str, param_types: &[u32], params: &[Option<Vec<u8>>], ) -> PgResult<()>
Execute an uncached query with explicit PostgreSQL parameter type OIDs and drain completion without materializing rows.
Sourcepub async fn query_rows(
&mut self,
sql: &str,
params: &[Option<Vec<u8>>],
) -> PgResult<Vec<PgRow>>
pub async fn query_rows( &mut self, sql: &str, params: &[Option<Vec<u8>>], ) -> PgResult<Vec<PgRow>>
Execute a query with bind parameters and return rows with column metadata.
Uses the Extended Query Protocol without prepared statement caching.
This is intended for raw SQL compatibility paths that still need
PgRow + ColumnInfo for name-aware JSON conversion.
Sourcepub async fn query_rows_with_result_format(
&mut self,
sql: &str,
params: &[Option<Vec<u8>>],
result_format: i16,
) -> PgResult<Vec<PgRow>>
pub async fn query_rows_with_result_format( &mut self, sql: &str, params: &[Option<Vec<u8>>], result_format: i16, ) -> PgResult<Vec<PgRow>>
Execute a query with bind parameters and explicit result-column format, returning rows with column metadata.
Sourcepub async fn query_visit_bytes_rows_with_result_format<F>(
&mut self,
sql: &str,
params: &[Option<Vec<u8>>],
result_format: i16,
on_row: F,
) -> PgResult<usize>
pub async fn query_visit_bytes_rows_with_result_format<F>( &mut self, sql: &str, params: &[Option<Vec<u8>>], result_format: i16, on_row: F, ) -> PgResult<usize>
Execute an uncached query and stream zero-copy rows to on_row.
This is the lowest-allocation raw-SQL path for large result sets when
the caller does not need PgRow materialization or column-name metadata.
Sourcepub async fn query_visit_first_column_bytes_with_result_format<F>(
&mut self,
sql: &str,
params: &[Option<Vec<u8>>],
result_format: i16,
on_value: F,
) -> PgResult<usize>
pub async fn query_visit_first_column_bytes_with_result_format<F>( &mut self, sql: &str, params: &[Option<Vec<u8>>], result_format: i16, on_value: F, ) -> PgResult<usize>
Execute an uncached query and stream only the first column of each row.
Sourcepub async fn query_rows_with_param_types_and_result_format(
&mut self,
sql: &str,
param_types: &[u32],
params: &[Option<Vec<u8>>],
result_format: i16,
) -> PgResult<Vec<PgRow>>
pub async fn query_rows_with_param_types_and_result_format( &mut self, sql: &str, param_types: &[u32], params: &[Option<Vec<u8>>], result_format: i16, ) -> PgResult<Vec<PgRow>>
Execute a query with explicit PostgreSQL parameter type OIDs and return rows with column metadata.
Sourcepub async fn query_visit_bytes_rows_with_param_types_and_result_format<F>(
&mut self,
sql: &str,
param_types: &[u32],
params: &[Option<Vec<u8>>],
result_format: i16,
on_row: F,
) -> PgResult<usize>
pub async fn query_visit_bytes_rows_with_param_types_and_result_format<F>( &mut self, sql: &str, param_types: &[u32], params: &[Option<Vec<u8>>], result_format: i16, on_row: F, ) -> PgResult<usize>
Execute an uncached query with explicit PostgreSQL parameter types and
stream zero-copy rows to on_row.
Rows are backed by one shared payload buffer plus column offsets, so the callback must not hold references past the current invocation.
Sourcepub async fn query_visit_first_column_bytes_with_param_types_and_result_format<F>(
&mut self,
sql: &str,
param_types: &[u32],
params: &[Option<Vec<u8>>],
result_format: i16,
on_value: F,
) -> PgResult<usize>
pub async fn query_visit_first_column_bytes_with_param_types_and_result_format<F>( &mut self, sql: &str, param_types: &[u32], params: &[Option<Vec<u8>>], result_format: i16, on_value: F, ) -> PgResult<usize>
Execute an uncached query with explicit PostgreSQL parameter types and stream only the first column of each row.
Sourcepub async fn probe_query_with_param_types(
&mut self,
sql: &str,
param_types: &[u32],
params: &[Option<Vec<u8>>],
) -> PgResult<()>
pub async fn probe_query_with_param_types( &mut self, sql: &str, param_types: &[u32], params: &[Option<Vec<u8>>], ) -> PgResult<()>
Validate a query with explicit PostgreSQL parameter type OIDs without executing it. Uses Parse + Bind + Describe(Portal) + Sync.
Sourcepub async fn query_cached(
&mut self,
sql: &str,
params: &[Option<Vec<u8>>],
) -> PgResult<Vec<Vec<Option<Vec<u8>>>>>
pub async fn query_cached( &mut self, sql: &str, params: &[Option<Vec<u8>>], ) -> PgResult<Vec<Vec<Option<Vec<u8>>>>>
Execute a query with cached prepared statement.
Like query(), but reuses prepared statements across calls.
The statement name is derived from a hash of the SQL text.
OPTIMIZED: Pre-allocated buffer + ultra-fast encoders.
Sourcepub async fn query_cached_with_result_format(
&mut self,
sql: &str,
params: &[Option<Vec<u8>>],
result_format: i16,
) -> PgResult<Vec<Vec<Option<Vec<u8>>>>>
pub async fn query_cached_with_result_format( &mut self, sql: &str, params: &[Option<Vec<u8>>], result_format: i16, ) -> PgResult<Vec<Vec<Option<Vec<u8>>>>>
Execute a query with cached prepared statement and explicit result-column format.
Sourcepub async fn execute_simple(&mut self, sql: &str) -> PgResult<()>
pub async fn execute_simple(&mut self, sql: &str) -> PgResult<()>
Execute a simple SQL statement (no parameters).
Sourcepub async fn simple_query(&mut self, sql: &str) -> PgResult<Vec<PgRow>>
pub async fn simple_query(&mut self, sql: &str) -> PgResult<Vec<PgRow>>
Execute a simple SQL query and return rows (Simple Query Protocol).
Unlike execute_simple, this collects and returns data rows.
Used for branch management and other administrative queries.
SECURITY: Capped at 10,000 rows to prevent OOM from unbounded results.
Sourcepub async fn query_prepared_single(
&mut self,
stmt: &PreparedStatement,
params: &[Option<Vec<u8>>],
) -> PgResult<Vec<Vec<Option<Vec<u8>>>>>
pub async fn query_prepared_single( &mut self, stmt: &PreparedStatement, params: &[Option<Vec<u8>>], ) -> PgResult<Vec<Vec<Option<Vec<u8>>>>>
ZERO-HASH sequential query using pre-computed PreparedStatement. This is the FASTEST sequential path because it skips:
- SQL generation from AST (done once outside loop)
- Hash computation for statement name (pre-computed in PreparedStatement)
- HashMap lookup for is_new check (statement already prepared)
§Example
let stmt = conn.prepare("SELECT * FROM users WHERE id = $1").await?;
for id in 1..10000 {
let rows = conn.query_prepared_single(&stmt, &[Some(id.to_string().into_bytes())]).await?;
}Sourcepub async fn query_prepared_single_count(
&mut self,
stmt: &PreparedStatement,
params: &[Option<Vec<u8>>],
) -> PgResult<()>
pub async fn query_prepared_single_count( &mut self, stmt: &PreparedStatement, params: &[Option<Vec<u8>>], ) -> PgResult<()>
ZERO-HASH sequential prepared execution that drains rows without materializing them.
Useful for throughput-focused paths where only protocol completion matters and result payload is intentionally ignored.
Sourcepub async fn query_prepared_single_with_result_format(
&mut self,
stmt: &PreparedStatement,
params: &[Option<Vec<u8>>],
result_format: i16,
) -> PgResult<Vec<Vec<Option<Vec<u8>>>>>
pub async fn query_prepared_single_with_result_format( &mut self, stmt: &PreparedStatement, params: &[Option<Vec<u8>>], result_format: i16, ) -> PgResult<Vec<Vec<Option<Vec<u8>>>>>
ZERO-HASH sequential query with explicit result-column format.
Sourcepub async fn query_prepared_single_reuse_with_result_format(
&mut self,
stmt: &PreparedStatement,
params: &[Option<Vec<u8>>],
result_format: i16,
) -> PgResult<Vec<Vec<Option<Vec<u8>>>>>
pub async fn query_prepared_single_reuse_with_result_format( &mut self, stmt: &PreparedStatement, params: &[Option<Vec<u8>>], result_format: i16, ) -> PgResult<Vec<Vec<Option<Vec<u8>>>>>
ZERO-HASH sequential query with explicit result-column format using
reusable connection buffers (avoids per-call BytesMut allocation).
Sourcepub async fn query_prepared_single_reuse_visit_rows_with_result_format<F>(
&mut self,
stmt: &PreparedStatement,
params: &[Option<Vec<u8>>],
result_format: i16,
on_row: F,
) -> PgResult<usize>
pub async fn query_prepared_single_reuse_visit_rows_with_result_format<F>( &mut self, stmt: &PreparedStatement, params: &[Option<Vec<u8>>], result_format: i16, on_row: F, ) -> PgResult<usize>
Sequential prepared query using reusable connection buffers and row visitor.
Rows are streamed to on_row as owned column buffers, avoiding
materializing the full result set.
Sourcepub async fn query_prepared_single_reuse_visit_bytes_rows_with_result_format<F>(
&mut self,
stmt: &PreparedStatement,
params: &[Option<Vec<u8>>],
result_format: i16,
on_row: F,
) -> PgResult<usize>
pub async fn query_prepared_single_reuse_visit_bytes_rows_with_result_format<F>( &mut self, stmt: &PreparedStatement, params: &[Option<Vec<u8>>], result_format: i16, on_row: F, ) -> PgResult<usize>
Sequential prepared query using reusable connection buffers and zero-copy row visitor.
Rows are backed by a shared payload buffer plus column offsets, avoiding per-cell byte copies during receive.
Sourcepub async fn query_prepared_single_reuse_visit_first_column_bytes_with_result_format<F>(
&mut self,
stmt: &PreparedStatement,
params: &[Option<Vec<u8>>],
result_format: i16,
on_value: F,
) -> PgResult<usize>
pub async fn query_prepared_single_reuse_visit_first_column_bytes_with_result_format<F>( &mut self, stmt: &PreparedStatement, params: &[Option<Vec<u8>>], result_format: i16, on_value: F, ) -> PgResult<usize>
Sequential prepared query using reusable buffers and first-column visitor.
Sourcepub async fn query_prepared_single_reuse_visit_first_four_columns_bytes_with_result_format<F>(
&mut self,
stmt: &PreparedStatement,
params: &[Option<Vec<u8>>],
result_format: i16,
on_row: F,
) -> PgResult<usize>
pub async fn query_prepared_single_reuse_visit_first_four_columns_bytes_with_result_format<F>( &mut self, stmt: &PreparedStatement, params: &[Option<Vec<u8>>], result_format: i16, on_row: F, ) -> PgResult<usize>
Sequential prepared query using reusable buffers and fixed 4-column visitor.
Sourcepub async fn query_prepared_single_encoded_visit_bytes_rows<F>(
&mut self,
wire: &[u8],
on_row: F,
) -> PgResult<usize>
pub async fn query_prepared_single_encoded_visit_bytes_rows<F>( &mut self, wire: &[u8], on_row: F, ) -> PgResult<usize>
Sequential prepared query from pre-encoded Bind/Execute/Sync wire bytes.
wire must contain exactly one prepared-statement execution.
Sourcepub async fn query_prepared_single_encoded_visit_bytes_rows_profiled<F>(
&mut self,
wire: &[u8],
on_row: F,
) -> PgResult<(usize, Duration, Duration)>
pub async fn query_prepared_single_encoded_visit_bytes_rows_profiled<F>( &mut self, wire: &[u8], on_row: F, ) -> PgResult<(usize, Duration, Duration)>
Sequential prepared query from pre-encoded Bind/Execute/Sync wire bytes.
Returns (rows, send_elapsed, consume_elapsed).
Sourcepub async fn query_prepared_single_encoded_visit_first_column_bytes<F>(
&mut self,
wire: &[u8],
on_value: F,
) -> PgResult<usize>
pub async fn query_prepared_single_encoded_visit_first_column_bytes<F>( &mut self, wire: &[u8], on_value: F, ) -> PgResult<usize>
Sequential prepared query from pre-encoded Bind/Execute/Sync wire bytes.
Sourcepub async fn query_prepared_single_encoded_visit_first_column_bytes_profiled<F>(
&mut self,
wire: &[u8],
on_value: F,
) -> PgResult<(usize, Duration, Duration)>
pub async fn query_prepared_single_encoded_visit_first_column_bytes_profiled<F>( &mut self, wire: &[u8], on_value: F, ) -> PgResult<(usize, Duration, Duration)>
Sequential prepared query from pre-encoded Bind/Execute/Sync wire bytes.
Returns (rows, send_elapsed, consume_elapsed).
Sourcepub async fn query_prepared_single_encoded_visit_first_four_columns_bytes<F>(
&mut self,
wire: &[u8],
on_row: F,
) -> PgResult<usize>
pub async fn query_prepared_single_encoded_visit_first_four_columns_bytes<F>( &mut self, wire: &[u8], on_row: F, ) -> PgResult<usize>
Sequential prepared query from pre-encoded Bind/Execute/Sync wire bytes.
Source§impl PgConnection
impl PgConnection
Sourcepub async fn identify_system(&mut self) -> PgResult<IdentifySystem>
pub async fn identify_system(&mut self) -> PgResult<IdentifySystem>
Run IDENTIFY_SYSTEM on a replication connection.
Sourcepub async fn create_logical_replication_slot(
&mut self,
slot_name: &str,
output_plugin: &str,
temporary: bool,
two_phase: bool,
) -> PgResult<ReplicationSlotInfo>
pub async fn create_logical_replication_slot( &mut self, slot_name: &str, output_plugin: &str, temporary: bool, two_phase: bool, ) -> PgResult<ReplicationSlotInfo>
Create a logical replication slot.
slot_name and output_plugin are strict SQL identifiers.
Sourcepub async fn drop_replication_slot(
&mut self,
slot_name: &str,
wait: bool,
) -> PgResult<()>
pub async fn drop_replication_slot( &mut self, slot_name: &str, wait: bool, ) -> PgResult<()>
Drop a replication slot.
wait=true uses DROP_REPLICATION_SLOT <slot> WAIT.
Sourcepub async fn start_logical_replication(
&mut self,
slot_name: &str,
start_lsn: &str,
options: &[ReplicationOption],
) -> PgResult<ReplicationStreamStart>
pub async fn start_logical_replication( &mut self, slot_name: &str, start_lsn: &str, options: &[ReplicationOption], ) -> PgResult<ReplicationStreamStart>
Start logical replication in CopyBoth mode.
Requires a connection started with replication=database.
Sourcepub async fn recv_replication_message(
&mut self,
) -> PgResult<ReplicationStreamMessage>
pub async fn recv_replication_message( &mut self, ) -> PgResult<ReplicationStreamMessage>
Receive the next logical replication stream message.
Uses a no-timeout read path so idle periods do not fail the stream.
Source§impl PgConnection
impl PgConnection
Sourcepub async fn begin_transaction(&mut self) -> PgResult<()>
pub async fn begin_transaction(&mut self) -> PgResult<()>
Begin a new transaction.
After calling this, all queries run within the transaction
until commit() or rollback() is called.
Sourcepub async fn commit(&mut self) -> PgResult<()>
pub async fn commit(&mut self) -> PgResult<()>
Commit the current transaction.
Makes all changes since begin_transaction() permanent.
Sourcepub async fn rollback(&mut self) -> PgResult<()>
pub async fn rollback(&mut self) -> PgResult<()>
Rollback the current transaction.
Discards all changes since begin_transaction().
Sourcepub async fn savepoint(&mut self, name: &str) -> PgResult<()>
pub async fn savepoint(&mut self, name: &str) -> PgResult<()>
Create a named savepoint within the current transaction.
Savepoints allow partial rollback within a transaction.
Use rollback_to() to return to this savepoint.
Sourcepub async fn rollback_to(&mut self, name: &str) -> PgResult<()>
pub async fn rollback_to(&mut self, name: &str) -> PgResult<()>
Rollback to a previously created savepoint. Discards all changes since the named savepoint was created, but keeps the transaction open.
Sourcepub async fn release_savepoint(&mut self, name: &str) -> PgResult<()>
pub async fn release_savepoint(&mut self, name: &str) -> PgResult<()>
Release a savepoint (free resources, if no longer needed).
Trait Implementations§
Source§impl Drop for PgConnection
Drop implementation sends Terminate packet if possible.
This ensures proper cleanup even without explicit close() call.
impl Drop for PgConnection
Drop implementation sends Terminate packet if possible. This ensures proper cleanup even without explicit close() call.