pub struct StatementModeHandler { /* private fields */ }Expand description
Statement mode handler
In statement mode, connections are returned to the pool after every statement outside of an explicit transaction. This provides maximum connection sharing but with significant limitations.
Benefits:
- Maximum connection sharing
- Best for high-volume simple queries
- Good for read-heavy workloads with many clients
Limitations:
- CANNOT use server-side prepared statements (Parse/Bind/Execute)
- CANNOT use LISTEN/NOTIFY
- CANNOT rely on session variables
- CANNOT use temp tables effectively
- Must use simple query protocol
Use cases:
- Connection poolers like PgBouncer in statement mode
- High-throughput REST APIs with simple queries
- Serverless environments with many concurrent clients
Implementations§
Source§impl StatementModeHandler
impl StatementModeHandler
Sourcepub fn with_autocommit(autocommit: bool) -> Self
pub fn with_autocommit(autocommit: bool) -> Self
Create with specific autocommit setting
Sourcepub fn create_lease(
&self,
connection: PooledConnection,
client_id: ClientId,
) -> ConnectionLease
pub fn create_lease( &self, connection: PooledConnection, client_id: ClientId, ) -> ConnectionLease
Create a lease for this mode
Sourcepub fn on_statement_complete(
&self,
lease: &mut ConnectionLease,
sql: &str,
) -> LeaseAction
pub fn on_statement_complete( &self, lease: &mut ConnectionLease, sql: &str, ) -> LeaseAction
Process a statement and determine action
Returns the connection after every statement outside of explicit transaction.
Sourcepub fn on_transaction_end(&self, lease: &mut ConnectionLease) -> LeaseAction
pub fn on_transaction_end(&self, lease: &mut ConnectionLease) -> LeaseAction
Process transaction end signal from backend
Sourcepub fn should_release(&self, lease: &ConnectionLease) -> bool
pub fn should_release(&self, lease: &ConnectionLease) -> bool
Check if connection should be released
Sourcepub fn on_client_disconnect(&self, _lease: ConnectionLease) -> LeaseAction
pub fn on_client_disconnect(&self, _lease: ConnectionLease) -> LeaseAction
Called when client disconnects
Sourcepub fn mode(&self) -> PoolingMode
pub fn mode(&self) -> PoolingMode
Get the pooling mode
Sourcepub fn autocommit(&self) -> bool
pub fn autocommit(&self) -> bool
Check if autocommit is enabled
Sourcepub fn tracks_prepared_statements(&self) -> bool
pub fn tracks_prepared_statements(&self) -> bool
Prepared statements are not supported in statement mode
Sourcepub fn is_safe_query(&self, sql: &str) -> bool
pub fn is_safe_query(&self, sql: &str) -> bool
Check if a query is safe for statement mode
Returns false for queries that require session state.
Sourcepub fn get_query_warning(&self, sql: &str) -> Option<&'static str>
pub fn get_query_warning(&self, sql: &str) -> Option<&'static str>
Get warning if query is unsafe for statement mode
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StatementModeHandler
impl RefUnwindSafe for StatementModeHandler
impl Send for StatementModeHandler
impl Sync for StatementModeHandler
impl Unpin for StatementModeHandler
impl UnsafeUnpin for StatementModeHandler
impl UnwindSafe for StatementModeHandler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more