From 1ec33ce5022c58a5ad079ed7f5c220fafe5f0a5f Mon Sep 17 00:00:00 2001 From: dull b Date: Wed, 26 Jul 2023 03:19:00 +0000 Subject: [PATCH] Revert "Attempt separate CrudBounds" This reverts commit 1b4ca321c3d2a1d045e2f4c542c593582e9c6d80. --- crates/db_schema/src/traits.rs | 73 ++++++++-------------------------- 1 file changed, 16 insertions(+), 57 deletions(-) diff --git a/crates/db_schema/src/traits.rs b/crates/db_schema/src/traits.rs index 12175477b..3f62f81ae 100644 --- a/crates/db_schema/src/traits.rs +++ b/crates/db_schema/src/traits.rs @@ -28,62 +28,10 @@ use std::{hash::Hash, pin::Pin}; /// Returned by `diesel::delete` pub type Delete = DeleteStatement<::Table, ::WhereClause>; -pub type Find = dsl::Find<::Table, IdType>; +pub type Find<'a, T> = dsl::Find<::Table, >::IdType>; -pub type InsertValues<'a, T, InsertForm> = - <&'a InsertForm as Insertable<::Table>>::Values; - -pub trait CrudBounds<'a, InsertForm, UpdateForm, IdType> -where - Self: HasTable + Sized, - Self::Table: FindDsl + 'static, - Find: LimitDsl + Send + IntoUpdateTarget + 'static, - dsl::Limit>: Send + LoadQuery<'static, AsyncPgConnection, Self> + 'static, - ::PrimaryKey: ExpressionMethods + Send, - <::PrimaryKey as Expression>::SqlType: SqlType + TypedExpressionType, - Delete>: ExecuteDsl + Send + 'static, - as IntoUpdateTarget>::WhereClause: 'static + Send, - as HasTable>::Table: 'static + Send, - &'a InsertForm: Insertable, - InsertValues<'a, Self, InsertForm>: 'a, - InsertStatement>: - LoadQuery<'a, AsyncPgConnection, Self> + 'a + Send, - InsertForm: 'static + Send + Sync, - UpdateForm: 'static + Send + Sync, - IdType: 'static - + Hash - + Eq - + Sized - + Send - + AsExpression<<::PrimaryKey as Expression>::SqlType>, -{ -} - -impl<'a, InsertForm, UpdateForm, IdType, T> CrudBounds<'a, InsertForm, UpdateForm, IdType> for T -where - Self: HasTable + Sized, - Self::Table: FindDsl + 'static, - Find: LimitDsl + Send + IntoUpdateTarget + 'static, - dsl::Limit>: Send + LoadQuery<'static, AsyncPgConnection, Self> + 'static, - ::PrimaryKey: ExpressionMethods + Send, - <::PrimaryKey as Expression>::SqlType: SqlType + TypedExpressionType, - Delete>: ExecuteDsl + Send + 'static, - as IntoUpdateTarget>::WhereClause: 'static + Send, - as HasTable>::Table: 'static + Send, - &'a InsertForm: Insertable, - InsertValues<'a, Self, InsertForm>: 'a, - InsertStatement>: - LoadQuery<'a, AsyncPgConnection, Self> + 'a + Send, - InsertForm: 'static + Send + Sync, - UpdateForm: 'static + Send + Sync, - IdType: 'static - + Hash - + Eq - + Sized - + Send - + AsExpression<<::PrimaryKey as Expression>::SqlType>, -{ -} +pub type InsertValues<'a, 'b, T> = + <&'a >::InsertForm as Insertable<::Table>>::Values; // When using `RunQueryDsl::execute`, directly building futures with `Box::pin` and `TryFutureExt::and_then` // instead of `async` + `await` fixes weird compile errors. @@ -93,8 +41,19 @@ where #[async_trait] pub trait Crud<'a> where - for<'b> Self: CrudBounds<'b, Self::InsertForm, Self::UpdateForm, Self::IdType>, - Self: Sized, + Self: HasTable + Sized, + for<'b> Self::Table: FindDsl<>::IdType> + 'static, + for<'b> Find<'b, Self>: LimitDsl + Send + IntoUpdateTarget + 'static, + for<'b> dsl::Limit>: Send + LoadQuery<'static, AsyncPgConnection, Self> + 'static, + ::PrimaryKey: ExpressionMethods + Send, + <::PrimaryKey as Expression>::SqlType: SqlType + TypedExpressionType, + for<'b> Delete>: ExecuteDsl + Send + 'static, + for<'b> as IntoUpdateTarget>::WhereClause: 'static + Send, + for<'b> as HasTable>::Table: 'static + Send, + for<'b> &'a >::InsertForm: Insertable, + for<'b> InsertValues<'a, 'b, Self>: 'a, + for<'b, 'query> InsertStatement>: + LoadQuery<'query, AsyncPgConnection, Self> + 'query + Send, { type InsertForm: 'static + Send + Sync; type UpdateForm: 'static + Send + Sync;