Skip to main content

Db

Trait Db 

Source
pub trait Db: MaybeSend + MaybeSync {
    type Tx<'a>: Tx
       where Self: 'a;

    // Required method
    fn begin(
        &self,
    ) -> impl Future<Output = Result<Self::Tx<'_>, DbError>> + MaybeSend;
}
Expand description

A database a request can open a transaction on.

Required Associated Types§

Source

type Tx<'a>: Tx where Self: 'a

A transaction on this database.

Required Methods§

Source

fn begin( &self, ) -> impl Future<Output = Result<Self::Tx<'_>, DbError>> + MaybeSend

Open a transaction. The connection is had here, before this returns, so one that cannot be had fails now rather than at the first statement. BEGIN is sent here or, by a driver that pipelines, with the first statement; nothing else is, so SET TRANSACTION may still follow, as the caller’s first statement. A connection that breaks after this is reported by the statement that finds out, as DbError::is_connection.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Db for PgPool

Source§

type Tx<'a> = SqlxTx

Source§

async fn begin(&self) -> Result<SqlxTx, DbError>

Implementors§