sqlx_utils/traits/repository/transactions/
delete_tx.rs

1use crate::filter::InValues;
2use crate::prelude::*;
3use std::future::Future;
4
5pub trait DeleteRepositoryTransaction<M: Model>:
6    DeleteRepository<M> + TransactionRepository<M>
7{
8    fn delete_by_id_in_transaction<'a>(
9        &'a self,
10        id: impl Into<M::Id> + Send + 'a,
11    ) -> impl Future<Output = Result<(), Error>> + Send + 'a
12    where
13        M::Id: 'a,
14    {
15        self.with_transaction(move |mut tx| async move {
16            let res = self.delete_by_id_with_executor(&mut *tx, id).await;
17
18            (res, tx)
19        })
20    }
21
22    fn delete_by_filter_in_transaction<'a>(
23        &'a self,
24        filter: impl SqlFilter<'a> + Send + 'a,
25    ) -> impl Future<Output = Result<(), Error>> + Send + 'a {
26        self.with_transaction(move |mut tx| async move {
27            let res = self.delete_by_filter_with_executor(&mut *tx, filter).await;
28
29            (res, tx)
30        })
31    }
32
33    fn delete_by_values_in_transaction<'a, I>(
34        &'a self,
35        column: &'static str,
36        values: I,
37    ) -> impl Future<Output = Result<(), Error>> + Send + 'a
38    where
39        M::Id: ::sqlx::Type<Database> + ::sqlx::Encode<'a, Database> + 'a,
40        I: IntoIterator<Item = M::Id> + Send + 'a,
41        I::IntoIter: Send + 'a,
42    {
43        let filter = InValues::new(column, values);
44
45        self.delete_by_filter_in_transaction(filter)
46    }
47}
48
49impl<T, M> DeleteRepositoryTransaction<M> for T
50where
51    T: DeleteRepository<M> + TransactionRepository<M>,
52    M: Model,
53{
54}