pub struct PgConnection { /* private fields */ }Expand description
A wrapper around a PostgreSQL connection with statement caching.
Implementations§
Source§impl PgConnection
impl PgConnection
Sourcepub async fn query(
&self,
sql: &str,
params: &[&(dyn ToSql + Sync)],
) -> PgResult<Vec<Row>>
pub async fn query( &self, sql: &str, params: &[&(dyn ToSql + Sync)], ) -> PgResult<Vec<Row>>
Execute a query and return all rows.
Sourcepub async fn query_one(
&self,
sql: &str,
params: &[&(dyn ToSql + Sync)],
) -> PgResult<Row>
pub async fn query_one( &self, sql: &str, params: &[&(dyn ToSql + Sync)], ) -> PgResult<Row>
Execute a query and return exactly one row.
Sourcepub async fn query_opt(
&self,
sql: &str,
params: &[&(dyn ToSql + Sync)],
) -> PgResult<Option<Row>>
pub async fn query_opt( &self, sql: &str, params: &[&(dyn ToSql + Sync)], ) -> PgResult<Option<Row>>
Execute a query and return zero or one row.
Sourcepub async fn execute(
&self,
sql: &str,
params: &[&(dyn ToSql + Sync)],
) -> PgResult<u64>
pub async fn execute( &self, sql: &str, params: &[&(dyn ToSql + Sync)], ) -> PgResult<u64>
Execute a statement and return the number of affected rows.
Sourcepub async fn batch_execute(&self, sql: &str) -> PgResult<()>
pub async fn batch_execute(&self, sql: &str) -> PgResult<()>
Execute a batch of statements in a single round-trip.
Sourcepub async fn notify(&self, channel: &str, payload: &str) -> PgResult<()>
pub async fn notify(&self, channel: &str, payload: &str) -> PgResult<()>
Send a notification on channel (SELECT pg_notify($1, $2)).
The channel name is matched verbatim (case preserved) by a
PgListener subscribed to the same
string. The name must be non-empty, at most 63 bytes and free of NUL,
and the payload shorter than 8000 bytes; both are checked before
anything is sent.
Sourcepub async fn transaction(&mut self) -> PgResult<PgTransaction<'_>>
pub async fn transaction(&mut self) -> PgResult<PgTransaction<'_>>
Begin a transaction.
Sourcepub fn inner(&self) -> &Object
pub fn inner(&self) -> &Object
Get the underlying tokio-postgres client.
This is useful for advanced operations not covered by this wrapper.
Sourcepub async fn query_cached(
&self,
sql: &str,
params: &[&(dyn ToSql + Sync)],
) -> PgResult<Vec<Row>>
pub async fn query_cached( &self, sql: &str, params: &[&(dyn ToSql + Sync)], ) -> PgResult<Vec<Row>>
Execute a query using the prepared statement cache.
This is an alias for query that makes it explicit that statement caching
is being used. All query methods already use prepared statement caching,
but this method name makes it more explicit for benchmark comparisons.