Trait sqlx_oldapi::Connection 
source · pub trait Connection: Send {
    type Database: Database;
    type Options: ConnectOptions<Connection = Self>;
    // Required methods
    fn close(
        self
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>;
    fn ping(
        &mut self
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_, Global>>;
    fn begin(
        &mut self
    ) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, Self::Database>, Error>> + Send + '_, Global>>
       where Self: Sized;
    // Provided methods
    fn transaction<'a, F, R, E>(
        &'a mut self,
        callback: F
    ) -> Pin<Box<dyn Future<Output = Result<R, E>> + Send + 'a, Global>>
       where F: for<'c> FnOnce(&'c mut Transaction<'_, Self::Database>) -> Pin<Box<dyn Future<Output = Result<R, E>> + Send + 'c, Global>> + 'a + Send + Sync,
             Self: Sized,
             R: Send,
             E: From<Error> + Send { ... }
    fn cached_statements_size(&self) -> usize
       where Self::Database: HasStatementCache { ... }
    fn clear_cached_statements(
        &mut self
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_, Global>>
       where Self::Database: HasStatementCache { ... }
    fn connect(
        url: &str
    ) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send, Global>>
       where Self: Sized { ... }
    fn connect_with(
        options: &Self::Options
    ) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + '_, Global>>
       where Self: Sized { ... }
}Expand description
Represents a single database connection.
Required Associated Types§
Required Methods§
sourcefn close(
    self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
 
fn close( self ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
Explicitly close this database connection.
This method is not required for safe and consistent operation. However, it is
recommended to call it instead of letting a connection drop as the database backend
will be faster at cleaning up resources.
Provided Methods§
sourcefn transaction<'a, F, R, E>(
    &'a mut self,
    callback: F
) -> Pin<Box<dyn Future<Output = Result<R, E>> + Send + 'a, Global>>where
    F: for<'c> FnOnce(&'c mut Transaction<'_, Self::Database>) -> Pin<Box<dyn Future<Output = Result<R, E>> + Send + 'c, Global>> + 'a + Send + Sync,
    Self: Sized,
    R: Send,
    E: From<Error> + Send,
 
fn transaction<'a, F, R, E>( &'a mut self, callback: F ) -> Pin<Box<dyn Future<Output = Result<R, E>> + Send + 'a, Global>>where F: for<'c> FnOnce(&'c mut Transaction<'_, Self::Database>) -> Pin<Box<dyn Future<Output = Result<R, E>> + Send + 'c, Global>> + 'a + Send + Sync, Self: Sized, R: Send, E: From<Error> + Send,
Execute the function inside a transaction.
If the function returns an error, the transaction will be rolled back. If it does not return an error, the transaction will be committed.
Example
use sqlx_core_oldapi::connection::Connection;
use sqlx_core_oldapi::error::Error;
use sqlx_core_oldapi::executor::Executor;
use sqlx_core_oldapi::postgres::{PgConnection, PgRow};
use sqlx_core_oldapi::query::query;
conn.transaction(|conn|Box::pin(async move {
    query("select * from ..").fetch_all(conn).await
})).awaitsourcefn cached_statements_size(&self) -> usizewhere
    Self::Database: HasStatementCache,
 
fn cached_statements_size(&self) -> usizewhere Self::Database: HasStatementCache,
The number of statements currently cached in the connection.
sourcefn clear_cached_statements(
    &mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_, Global>>where
    Self::Database: HasStatementCache,
 
fn clear_cached_statements( &mut self ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_, Global>>where Self::Database: HasStatementCache,
Removes all statements from the cache, closing them on the server if needed.