pub async fn transaction<F, Fut, R>(pool: &PgPool, f: F) -> OrmResult<R>Expand description
Выполняет асинхронную функцию внутри транзакции. При ошибке откатывает, при успехе — коммитит.
let (user, profile) = orm::transaction(&pool, |tx| async move {
let user = User::create(data, tx).await?;
let profile = Profile::create(NewProfile { user_id: user.id }, tx).await?;
Ok((user, profile))
}).await?;