Example of using a transaction
This commit is contained in:
parent
1d6e6066cd
commit
608a49292f
@ -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.")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user