[][src]Trait sqlx::Connection

pub trait Connection: Send + 'static + Executor {
    fn close(
        self
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send>>;
fn ping(
        &mut self
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>; fn begin(
        self
    ) -> Pin<Box<dyn Future<Output = Result<Transaction<Self>, Error>> + 'static + Send>> { ... } }

Represents a single database connection rather than a pool of database connections.

Connections can be manually established outside of a Pool with Connect::connect.

Prefer running queries from Pool unless there is a specific need for a single, sticky connection.

Required methods

fn close(
    self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send>>

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 server will be faster at cleaning up resources.

fn ping(&mut self) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>

Checks if a connection to the database is still valid.

Loading content...

Provided methods

fn begin(
    self
) -> Pin<Box<dyn Future<Output = Result<Transaction<Self>, Error>> + 'static + Send>>

Starts a new transaction.

Wraps this connection in Transaction to manage the transaction lifecycle. To get the original connection back, explicitly commit or rollback and this connection will be returned.

ⓘThis example is not tested
let mut tx = conn.begin().await?;
// conn is now inaccessible as its wrapped in a transaction

let conn = tx.commit().await?;
// conn is back now and out of the transaction
Loading content...

Implementors

impl Connection for MySqlConnection[src]

impl Connection for PgConnection[src]

impl Connection for SqliteConnection[src]

impl<C> Connection for PoolConnection<C> where
    C: Connect
[src]

impl<C> Connection for Transaction<C> where
    C: Connection
[src]

Loading content...