works properly
This commit is contained in:
@@ -52,14 +52,14 @@ pub mod crud {
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait Delete<'c>: Sized {
|
||||
type Id;
|
||||
type Filter;
|
||||
pub trait Delete: Sized {
|
||||
type Id: Send + Copy;
|
||||
type Filter: Send + Sync;
|
||||
|
||||
async fn delete<T>(
|
||||
async fn delete<'c, T>(
|
||||
ctx: &Context,
|
||||
db: T,
|
||||
filter: Self::Filter,
|
||||
filter: &Self::Filter,
|
||||
id: Self::Id,
|
||||
) -> Result<bool, Error>
|
||||
where
|
||||
@@ -74,19 +74,29 @@ pub mod crud {
|
||||
// * A transaction will begin() (a noop) and then acquire() a new connection
|
||||
T: sqlx::Acquire<'c, Database = sqlx::Sqlite> + Send + std::fmt::Debug;
|
||||
|
||||
// async fn delete_all(
|
||||
// ctx: &Context,
|
||||
// pool: &sqlite::Pool,
|
||||
// filter: Self::Filter,
|
||||
// ids: Vec<Self::Id>,
|
||||
// ) -> Result<bool, Error> {
|
||||
// let mut transaction = pool.begin().await?;
|
||||
async fn delete_all<'c>(
|
||||
// &self,
|
||||
ctx: &Context,
|
||||
pool: &'c sqlite::Pool,
|
||||
filter: Self::Filter,
|
||||
ids: Vec<Self::Id>,
|
||||
) -> Result<bool, Error> {
|
||||
use sqlx::Acquire as _;
|
||||
|
||||
// for id in ids {
|
||||
// Self::delete(ctx, Box::new(&mut *transaction), filter, id).await?;
|
||||
// }
|
||||
// unimplemented!()
|
||||
// }
|
||||
let mut transaction = pool.begin().await?;
|
||||
let conn = transaction.acquire().await?;
|
||||
|
||||
for id in ids {
|
||||
if !Self::delete(ctx, &mut *conn, &filter, id).await? {
|
||||
// transaction will rollback on drop
|
||||
return Ok(false);
|
||||
}
|
||||
}
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user