Skip to main content

PoolGuard

Struct PoolGuard 

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

A borrowed connection from the pool. Returns to the pool on drop.

If the connection is in a failed transaction state, broken, or marked for discard, it is dropped (decrements open_count) instead of returned.

PoolGuard dispatches query methods to either the async Connection or the sync SyncConnection depending on the underlying slot type. For sync connections, blocking I/O is wrapped in tokio::task::block_in_place.

Implementations§

Source§

impl PoolGuard

Source

pub fn mark_discard(&mut self)

Mark this connection for discard — it will NOT be returned to the pool on drop. The open_count is decremented and the TCP connection is closed.

Used by streaming queries that are dropped mid-iteration: the connection may be in an indeterminate protocol state (portal open, no ReadyForQuery) and cannot be safely reused.

Source

pub async fn cancel(&self) -> Result<(), DriverError>

Cancel the currently running query on the underlying connection.

Opens a new TCP connection and sends a CancelRequest to PG. The cancel connection is closed immediately after.

Source

pub fn pid(&self) -> i32

Get the backend process ID for this connection.

Source

pub fn is_idle(&self) -> bool

Whether the connection is idle (not in a transaction).

Source

pub fn is_in_transaction(&self) -> bool

Whether the connection is inside a transaction.

Source

pub async fn query( &mut self, sql: &str, sql_hash: u64, params: &[&(dyn Encode + Sync)], arena: &mut Arena, ) -> Result<QueryResult, DriverError>

Execute a prepared query and return rows in arena-allocated storage.

Source

pub async fn execute( &mut self, sql: &str, sql_hash: u64, params: &[&(dyn Encode + Sync)], ) -> Result<u64, DriverError>

Execute a query without result rows (INSERT/UPDATE/DELETE).

For sync UDS connections, calls execute_monolithic directly — the entire send+receive path is inlined in one function.

Source

pub async fn execute_pipeline( &mut self, sql: &str, sql_hash: u64, param_sets: &[&[&(dyn Encode + Sync)]], ) -> Result<Vec<u64>, DriverError>

Execute the same statement N times with different params in one pipeline.

Sends all N Bind+Execute messages + one Sync. One round-trip for N operations. Returns the affected row count for each parameter set.

Source

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

Execute a simple (unprepared) query.

Source

pub async fn for_each<F>( &mut self, sql: &str, sql_hash: u64, params: &[&(dyn Encode + Sync)], f: F, ) -> Result<(), DriverError>
where F: FnMut(PgDataRow<'_>) -> Result<(), DriverError>,

Process each row via a closure with zero-copy PgDataRow.

Source

pub async fn for_each_raw<F>( &mut self, sql: &str, sql_hash: u64, params: &[&(dyn Encode + Sync)], f: F, ) -> Result<(), DriverError>
where F: FnMut(&[u8]) -> Result<(), DriverError>,

Process each DataRow as raw bytes — fastest path.

For sync UDS connections, calls for_each_raw_monolithic directly — the entire send+receive path is inlined in one function.

Source

pub async fn query_streaming_start( &mut self, sql: &str, sql_hash: u64, params: &[&(dyn Encode + Sync)], chunk_size: i32, ) -> Result<(Arc<[ColumnDesc]>, bool), DriverError>

Start a streaming query. Only available on async connections.

Returns an error if called on a sync UDS connection (streaming requires the async protocol’s portal suspend/resume mechanism).

Source

pub async fn streaming_send_execute( &mut self, chunk_size: i32, ) -> Result<(), DriverError>

Send Execute+Flush for a streaming query (2nd+ chunks).

Source

pub async fn streaming_next_chunk( &mut self, arena: &mut Arena, all_col_offsets: &mut Vec<(usize, i32)>, ) -> Result<bool, DriverError>

Read the next chunk of rows from an in-progress streaming query.

Source

pub fn is_sync(&self) -> bool

Whether this guard holds a sync (UDS) connection.

Useful for callers that need to know the connection type (e.g., to choose between streaming and non-streaming query paths).

Trait Implementations§

Source§

impl Drop for PoolGuard

Source§

fn drop(&mut self)

Executes the destructor for this type. 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, 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.