AtomicOperation

Trait AtomicOperation 

Source
pub trait AtomicOperation: Send {
    // Required method
    fn as_executor(&mut self) -> &mut PgConnection;

    // Provided method
    fn now(&self) -> Option<DateTime<Utc>> { ... }
}
Expand description

Trait to signify we can make multiple consistent database roundtrips.

Its a stand in for &mut sqlx::Transaction<'_, DB>. The reason for having a trait is to support custom types that wrap the inner transaction while providing additional functionality.

See DbOp or DbOpWithTime.

Required Methods§

Source

fn as_executor(&mut self) -> &mut PgConnection

Returns the sqlx::Executor implementation. The desired way to represent this would actually be as a GAT:

trait AtomicOperation {
    type Executor<'c>: sqlx::PgExecutor<'c>
        where Self: 'c;

    fn as_executor<'c>(&'c mut self) -> Self::Executor<'c>;
}

But GATs don’t play well with async_trait::async_trait due to lifetime constraints so we return the concrete &mut sqlx::PgConnection instead as a work around.

Since this trait is generally applied to types that wrap a sqlx::Transaction there is no variance in the return type - so its fine.

Provided Methods§

Source

fn now(&self) -> Option<DateTime<Utc>>

Function for querying when the operation is taking place - if it is cached.

Implementations on Foreign Types§

Source§

impl<'c> AtomicOperation for PgTransaction<'c>

Source§

fn as_executor(&mut self) -> &mut PgConnection

Implementors§