sqlx_utils/traits/repository/transactions/
update_tx.rs

1use crate::prelude::*;
2use std::future::Future;
3
4pub trait UpdatableRepositoryTransaction<M: Model>:
5    UpdatableRepository<M> + TransactionRepository<M>
6{
7    fn update_in_transaction<'a>(
8        &'a self,
9        model: M,
10    ) -> impl Future<Output = Result<M, Error>> + Send + 'a
11    where
12        M: 'a,
13    {
14        self.with_transaction(move |mut tx| async move {
15            let res = self.update_with_executor(&mut *tx, model).await;
16
17            (res, tx)
18        })
19    }
20
21    fn update_ref_in_transaction<'a, 'b>(
22        &'a self,
23        model: &'b M,
24    ) -> impl Future<Output = Result<(), Error>> + Send + 'a
25    where
26        'b: 'a,
27        M: 'b,
28    {
29        self.with_transaction(move |mut tx| async move {
30            let res = self.update_ref_with_executor(&mut *tx, model).await;
31
32            (res, tx)
33        })
34    }
35}