mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-25 07:36:01 +00:00
Fix Crud::delete
This commit is contained in:
parent
c1ad7a161b
commit
3abcce2eec
|
@ -21,7 +21,8 @@ use diesel_async::{
|
|||
AsyncPgConnection,
|
||||
RunQueryDsl,
|
||||
};
|
||||
use std::hash::Hash;
|
||||
use futures_util::{Future, TryFutureExt};
|
||||
use std::{hash::Hash, pin::Pin};
|
||||
|
||||
/// Returned by `diesel::delete`
|
||||
pub type Delete<T> = DeleteStatement<<T as HasTable>::Table, <T as IntoUpdateTarget>::WhereClause>;
|
||||
|
@ -33,12 +34,13 @@ pub trait Crud<'a>
|
|||
where
|
||||
Self: HasTable + Sized,
|
||||
for<'b> Self::Table: FindDsl<<Self as Crud<'b>>::IdType> + 'static,
|
||||
for<'b> Find<'b, Self>: LimitDsl + Send + IntoUpdateTarget + 'b,
|
||||
for<'b, 'query> dsl::Limit<Find<'b, Self>>:
|
||||
Send + LoadQuery<'query, AsyncPgConnection, Self> + 'query,
|
||||
for<'b> Find<'b, Self>: LimitDsl + Send + IntoUpdateTarget + 'static,
|
||||
for<'b> dsl::Limit<Find<'b, Self>>: Send + LoadQuery<'static, AsyncPgConnection, Self> + 'static,
|
||||
<Self::Table as Table>::PrimaryKey: ExpressionMethods + Send,
|
||||
<<Self::Table as Table>::PrimaryKey as Expression>::SqlType: SqlType + TypedExpressionType,
|
||||
for<'b> Delete<Find<'b, Self>>: ExecuteDsl<AsyncPgConnection> + Send + 'b,
|
||||
for<'b> Delete<Find<'b, Self>>: ExecuteDsl<AsyncPgConnection> + Send + 'static,
|
||||
for<'b> <Find<'b, Self> as IntoUpdateTarget>::WhereClause: 'static + Send,
|
||||
for<'b> <Find<'b, Self> as HasTable>::Table: 'static + Send,
|
||||
{
|
||||
/*for<'a> &'a Self::InsertForm: Insertable<Self::Table>,
|
||||
for<'a> InsertStatement<Self::Table, <&'a Self::InsertForm as Insertable<Self::Table>>::Values>:
|
||||
|
@ -46,7 +48,8 @@ where
|
|||
for<'a> <&'a Self::InsertForm as Insertable<Self::Table>>::Values: 'a,*/
|
||||
type InsertForm;
|
||||
type UpdateForm;
|
||||
type IdType: Hash
|
||||
type IdType: 'static
|
||||
+ Hash
|
||||
+ Eq
|
||||
+ Sized
|
||||
+ Send
|
||||
|
@ -82,13 +85,18 @@ where
|
|||
.get_result::<Self>(conn)
|
||||
.await
|
||||
}*/
|
||||
async fn delete(pool: &mut DbPool<'_>, id: Self::IdType) -> Result<usize, Error>
|
||||
fn delete<'life0, 'life1, 'async_trait>(
|
||||
pool: &'life0 mut DbPool<'life1>,
|
||||
id: Self::IdType,
|
||||
) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>
|
||||
where
|
||||
'a: 'async_trait,
|
||||
'life0: 'async_trait,
|
||||
'life1: 'async_trait,
|
||||
Self: Send + 'async_trait,
|
||||
{
|
||||
let query = diesel::delete(Self::table().find(id));
|
||||
let conn = &mut *get_conn(pool).await?;
|
||||
query.execute(conn).await
|
||||
let query: Delete<Find<'a, Self>> = diesel::delete(Self::table().find(id));
|
||||
Box::pin(get_conn(pool).and_then(move |mut conn| query.execute(&mut *conn)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue