Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
fix: implement transaction according to diesel_async readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushuo committed Feb 17, 2024
1 parent 2289911 commit eed5e1c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions backend/src/model/entity/plantings_impl.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! Contains the implementation of [`Planting`].
use std::future::Future;

use chrono::NaiveDate;
use diesel::pg::Pg;
use diesel::{
debug_query, BoolExpressionMethods, ExpressionMethods, NullableExpressionMethods, QueryDsl,
QueryResult,
};
use diesel_async::scoped_futures::ScopedFutureExt;
use diesel_async::{AsyncConnection, AsyncPgConnection, RunQueryDsl};
use futures_util::Future;
use log::debug;
use uuid::Uuid;

Expand Down Expand Up @@ -155,13 +157,14 @@ impl Planting {

let result = conn
.transaction(|transaction| {
Box::pin(async {
async move {
let futures = Self::do_update(planting_updates, transaction);

let results = futures_util::future::try_join_all(futures).await?;

Ok(results) as QueryResult<Vec<Self>>
})
}
.scope_boxed()
})
.await?;

Expand Down

0 comments on commit eed5e1c

Please sign in to comment.