Skip to main content

Database

Trait Database 

Source
pub trait Database {
    // Required methods
    async fn connection(
        &mut self,
    ) -> Result<&mut RawPgConnection, DatabaseError>;
    async fn begin_transaction<'d>(
        &'d mut self,
    ) -> Result<TransactedDb<'d>, DatabaseError>;
}
Expand description

Provides access to a connection. Should be called by extension traits but not from application code.

Usually we don’t need to use this directly, so prefer underscore for imports.

Required Methods§

Source

async fn connection(&mut self) -> Result<&mut RawPgConnection, DatabaseError>

Acquires a new connection from the pool.

TransactedDb::commit

Source

async fn begin_transaction<'d>( &'d mut self, ) -> Result<TransactedDb<'d>, DatabaseError>

Starts a new transaction, acquiring a fresh connection from the pool Once a transaction has been started, it is the callers’ responsibility to make changes permanent by committing it. If the transaction is dropped without being committed, all changes are rolled back.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§