diff --git a/crates/db_schema/src/traits.rs b/crates/db_schema/src/traits.rs index 3e1ee2207..7cafaef7f 100644 --- a/crates/db_schema/src/traits.rs +++ b/crates/db_schema/src/traits.rs @@ -7,6 +7,7 @@ use diesel::{ dsl, expression::{AsExpression, TypedExpressionType}, expression_methods::ExpressionMethods, + query_builder::{DeleteStatement, IntoUpdateTarget}, query_dsl::methods::{FindDsl, LimitDsl}, result::Error, sql_types::SqlType, @@ -15,9 +16,16 @@ use diesel::{ Insertable, Table, }; -use diesel_async::{methods::LoadQuery, AsyncPgConnection, RunQueryDsl}; +use diesel_async::{ + methods::{ExecuteDsl, LoadQuery}, + AsyncPgConnection, + RunQueryDsl, +}; use std::hash::Hash; +/// Returned by `diesel::delete` +pub type Delete = DeleteStatement<::Table, ::WhereClause>; + /*Self: Send + 'static + Sized + HasTable, Self::Table: FindDsl + Send + Sized + 'static, @@ -30,12 +38,13 @@ pub trait Crud where Self: HasTable + Sized, Self::Table: FindDsl + 'static, - dsl::Find: LimitDsl + Send, + dsl::Find: LimitDsl + Send + IntoUpdateTarget, for<'a> dsl::Limit>: Send + LoadQuery<'a, AsyncPgConnection, Self> + 'a, <::Table as Table>::PrimaryKey: ExpressionMethods + Send, <<::Table as Table>::PrimaryKey as Expression>::SqlType: SqlType + TypedExpressionType, + for<'a> Delete>: ExecuteDsl + 'a + Send, { /*for<'a> &'a Self::InsertForm: Insertable, for<'a> InsertStatement>::Values>: @@ -72,10 +81,10 @@ where .get_result::(conn) .await }*/ - async fn delete(_pool: &mut DbPool<'_>, _id: Self::IdType) -> Result { - Err(Error::NotFound) - /*let conn = &mut get_conn(pool).await?; - diesel::delete(Self::table().find(id)).execute(conn).await*/ + async fn delete(pool: &mut DbPool<'_>, id: Self::IdType) -> Result { + let query = diesel::delete(Self::table().find(id)); + let conn = &mut *get_conn(pool).await?; + query.execute(conn).await } }