From c1ad7a161bbc8495dbfb8b52073f35ae88519da6 Mon Sep 17 00:00:00 2001 From: dull b Date: Tue, 25 Jul 2023 02:35:35 +0000 Subject: [PATCH] Fix lifetime for everything except Crud::delete --- crates/db_schema/src/traits.rs | 46 ++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/crates/db_schema/src/traits.rs b/crates/db_schema/src/traits.rs index 3084abe7a..b7702acba 100644 --- a/crates/db_schema/src/traits.rs +++ b/crates/db_schema/src/traits.rs @@ -26,25 +26,19 @@ 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, ->::Output: -LimitDsl + Send + Sized + 'static, -<::PrimaryKey as Expression>::SqlType: SqlType, -::PrimaryKey: ExpressionMethods + Send + Sized + 'static,*/ +pub type Find<'a, T> = dsl::Find<::Table, >::IdType>; + #[async_trait] pub trait Crud<'a> where Self: HasTable + Sized, - Self::Table: FindDsl + 'static, - dsl::Find: LimitDsl + Send + IntoUpdateTarget, - for<'query> dsl::Limit>: + for<'b> Self::Table: FindDsl<>::IdType> + 'static, + for<'b> Find<'b, Self>: LimitDsl + Send + IntoUpdateTarget + 'b, + for<'b, 'query> dsl::Limit>: Send + LoadQuery<'query, AsyncPgConnection, Self> + 'query, - <::Table as Table>::PrimaryKey: ExpressionMethods + Send, - <<::Table as Table>::PrimaryKey as Expression>::SqlType: - SqlType + TypedExpressionType, - for<'a> Delete>: ExecuteDsl + 'a + Send, + ::PrimaryKey: ExpressionMethods + Send, + <::PrimaryKey as Expression>::SqlType: SqlType + TypedExpressionType, + for<'b> Delete>: ExecuteDsl + Send + 'b, { /*for<'a> &'a Self::InsertForm: Insertable, for<'a> InsertStatement>::Values>: @@ -57,13 +51,18 @@ where + Sized + Send + AsExpression<<::PrimaryKey as Expression>::SqlType>; - async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result; + async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result + where + 'a: 'async_trait; /*{ let query = insert_into(Self::table()).values(form); let conn = &mut *get_conn(pool).await?; query.get_result::(conn).await }*/ - async fn read(pool: &mut DbPool<'_>, id: Self::IdType) -> Result { + async fn read(pool: &mut DbPool<'_>, id: Self::IdType) -> Result + where + 'a: 'async_trait, + { let query = Self::table().find(id); let conn = &mut *get_conn(pool).await?; query.first::(conn).await @@ -73,15 +72,20 @@ where pool: &mut DbPool<'_>, id: Self::IdType, form: &'a Self::UpdateForm, - ) -> Result; + ) -> Result + where + 'a: 'async_trait; /*{ let conn = &mut get_conn(pool).await?; diesel::update(Self::table().find(id)) - .set(form) - .get_result::(conn) - .await + .set(form) + .get_result::(conn) + .await }*/ - async fn delete(pool: &mut DbPool<'_>, id: Self::IdType) -> Result { + async fn delete(pool: &mut DbPool<'_>, id: Self::IdType) -> Result + where + 'a: 'async_trait, + { let query = diesel::delete(Self::table().find(id)); let conn = &mut *get_conn(pool).await?; query.execute(conn).await