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.

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.

Source

pub 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 fn query( &mut self, sql: &str, sql_hash: u64, params: &[&(dyn Encode + Sync)], ) -> Result<QueryResult, DriverError>

Execute a prepared query and return rows.

Source

pub 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).

Source

pub 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 fn simple_query(&mut self, sql: &str) -> Result<(), DriverError>

Execute a simple (unprepared) query.

Source

pub fn simple_query_rows( &mut self, sql: &str, ) -> Result<Vec<SimpleRow>, DriverError>

Execute a simple query and return rows as text.

Uses PostgreSQL’s simple query protocol — all values are strings.

Source

pub 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 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.

Source

pub 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.

Source

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

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

Source

pub 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 copy_in<'a, I>( &mut self, table: &str, columns: &[&str], rows: I, ) -> Result<u64, DriverError>
where I: IntoIterator<Item = &'a str>,

Bulk copy data INTO a table from an iterator of text rows.

Each row is a tab-separated string (TSV format). Returns the row count.

Source

pub fn copy_out<W: Write>( &mut self, query: &str, writer: &mut W, ) -> Result<u64, DriverError>

Bulk copy data OUT of a table/query to a writer.

Writes TSV-formatted rows. Returns the row count.

Source

pub fn is_sync(&self) -> bool

Whether this guard holds a sync connection.

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.