atomic

Attribute Macro atomic 

Source
#[atomic]
Expand description

Attribute macro for atomic transactions

Wraps the function body in a transaction.

§Usage

#[atomic(db)]
async fn create_user(db: &DatabaseConnection, name: String) -> Result<(), OrmadaError> {
    // This code runs inside a transaction!
    // 'db' is shadowed by the transaction handle
    let user = User::objects(db).create(name).await?;
    Ok(())
}