Struct deadpool_postgres::StatementCache
source · pub struct StatementCache { /* private fields */ }
Expand description
Representation of a cache of Statement
s.
StatementCache
is bound to one Client
, and Statement
s generated
by that Client
must not be used with other Client
s.
It can be used like that:
let client = pool.get().await?;
let stmt = client
.statement_cache
.prepare(&client, "SELECT 1")
.await;
let rows = client.query(stmt, &[]).await?;
...
Normally, you probably want to use the ClientWrapper::prepare_cached()
and ClientWrapper::prepare_typed_cached()
methods instead (or the
similar ones on Transaction
).
Implementations§
source§impl StatementCache
impl StatementCache
sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Returns current size of this StatementCache
.
sourcepub fn clear(&self)
pub fn clear(&self)
Clears this StatementCache
.
Important: This only clears the StatementCache
of one Client
instance. If you want to clear the StatementCache
of all Client
s
you should be calling pool.manager().statement_caches.clear()
instead.
sourcepub fn remove(&self, query: &str, types: &[Type]) -> Option<Statement>
pub fn remove(&self, query: &str, types: &[Type]) -> Option<Statement>
Removes a Statement
from this StatementCache
.
Important: This only removes a Statement
from one Client
cache. If you want to remove a Statement
from all
StatementCaches
you should be calling
pool.manager().statement_caches.remove()
instead.
sourcepub async fn prepare(
&self,
client: &PgClient,
query: &str
) -> Result<Statement, Error>
pub async fn prepare(
&self,
client: &PgClient,
query: &str
) -> Result<Statement, Error>
Creates a new prepared Statement
using this StatementCache
, if
possible.