mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-25 20:31:31 +00:00
Default Crud::delete
This commit is contained in:
parent
25a27165a8
commit
c37cd3ccd9
1 changed files with 15 additions and 6 deletions
|
@ -7,6 +7,7 @@ use diesel::{
|
||||||
dsl,
|
dsl,
|
||||||
expression::{AsExpression, TypedExpressionType},
|
expression::{AsExpression, TypedExpressionType},
|
||||||
expression_methods::ExpressionMethods,
|
expression_methods::ExpressionMethods,
|
||||||
|
query_builder::{DeleteStatement, IntoUpdateTarget},
|
||||||
query_dsl::methods::{FindDsl, LimitDsl},
|
query_dsl::methods::{FindDsl, LimitDsl},
|
||||||
result::Error,
|
result::Error,
|
||||||
sql_types::SqlType,
|
sql_types::SqlType,
|
||||||
|
@ -15,9 +16,16 @@ use diesel::{
|
||||||
Insertable,
|
Insertable,
|
||||||
Table,
|
Table,
|
||||||
};
|
};
|
||||||
use diesel_async::{methods::LoadQuery, AsyncPgConnection, RunQueryDsl};
|
use diesel_async::{
|
||||||
|
methods::{ExecuteDsl, LoadQuery},
|
||||||
|
AsyncPgConnection,
|
||||||
|
RunQueryDsl,
|
||||||
|
};
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
|
/// Returned by `diesel::delete`
|
||||||
|
pub type Delete<T> = DeleteStatement<<T as HasTable>::Table, <T as IntoUpdateTarget>::WhereClause>;
|
||||||
|
|
||||||
/*Self: Send + 'static + Sized + HasTable,
|
/*Self: Send + 'static + Sized + HasTable,
|
||||||
Self::Table:
|
Self::Table:
|
||||||
FindDsl<Self::IdType> + Send + Sized + 'static,
|
FindDsl<Self::IdType> + Send + Sized + 'static,
|
||||||
|
@ -30,12 +38,13 @@ pub trait Crud
|
||||||
where
|
where
|
||||||
Self: HasTable + Sized,
|
Self: HasTable + Sized,
|
||||||
Self::Table: FindDsl<Self::IdType> + 'static,
|
Self::Table: FindDsl<Self::IdType> + 'static,
|
||||||
dsl::Find<Self::Table, Self::IdType>: LimitDsl + Send,
|
dsl::Find<Self::Table, Self::IdType>: LimitDsl + Send + IntoUpdateTarget,
|
||||||
for<'a> dsl::Limit<dsl::Find<Self::Table, Self::IdType>>:
|
for<'a> dsl::Limit<dsl::Find<Self::Table, Self::IdType>>:
|
||||||
Send + LoadQuery<'a, AsyncPgConnection, Self> + 'a,
|
Send + LoadQuery<'a, AsyncPgConnection, Self> + 'a,
|
||||||
<<Self as HasTable>::Table as Table>::PrimaryKey: ExpressionMethods + Send,
|
<<Self as HasTable>::Table as Table>::PrimaryKey: ExpressionMethods + Send,
|
||||||
<<<Self as HasTable>::Table as Table>::PrimaryKey as Expression>::SqlType:
|
<<<Self as HasTable>::Table as Table>::PrimaryKey as Expression>::SqlType:
|
||||||
SqlType + TypedExpressionType,
|
SqlType + TypedExpressionType,
|
||||||
|
for<'a> Delete<dsl::Find<Self::Table, Self::IdType>>: ExecuteDsl<AsyncPgConnection> + 'a + 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>:
|
||||||
|
@ -72,10 +81,10 @@ where
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}*/
|
}*/
|
||||||
async fn delete(_pool: &mut DbPool<'_>, _id: Self::IdType) -> Result<usize, Error> {
|
async fn delete(pool: &mut DbPool<'_>, id: Self::IdType) -> Result<usize, Error> {
|
||||||
Err(Error::NotFound)
|
let query = diesel::delete(Self::table().find(id));
|
||||||
/*let conn = &mut get_conn(pool).await?;
|
let conn = &mut *get_conn(pool).await?;
|
||||||
diesel::delete(Self::table().find(id)).execute(conn).await*/
|
query.execute(conn).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue