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