[][src]Trait sqlx::prelude::Connection

pub trait Connection: Send + 'static + Executor {
    fn close(
        self
    ) -> Pin<Box<dyn Future<Output = Result<(), Error<Self::Database>>> + 'static + Send>>;
fn ping(
        &mut self
    ) -> Pin<Box<dyn Future<Output = Result<(), Error<Self::Database>>> + Send>>; fn begin(
        self
    ) -> Pin<Box<dyn Future<Output = Result<Transaction<Self>, Error<Self::Database>>> + '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<Self::Database>>> + '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<Self::Database>>> + 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<Self::Database>>> + '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<C> Connection for PoolConnection<C> where
    C: Connect
[src]

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

Loading content...