Example of using a transaction

This commit is contained in:
Chris Tsang 2021-10-13 16:51:12 +08:00
parent 1d6e6066cd
commit 608a49292f

View File

@ -59,14 +59,22 @@ async fn update(
let form = post_form.into_inner(); let form = post_form.into_inner();
post::ActiveModel { db.transaction::<_, (), sea_orm::DbErr>(|txn| {
id: post.id, Box::pin(async move {
title: Set(form.title.to_owned()), post::ActiveModel {
text: Set(form.text.to_owned()), id: post.id,
} title: Set(form.title.to_owned()),
.save(db) text: Set(form.text.to_owned()),
}
.save(txn)
.await
.expect("could not edit post");
Ok(())
})
})
.await .await
.expect("could not edit post"); .unwrap();
Flash::success(Redirect::to("/"), "Post successfully edited.") Flash::success(Redirect::to("/"), "Post successfully edited.")
} }