From 3b3540cb27c63fad07368734a8a73d62c15f4664 Mon Sep 17 00:00:00 2001 From: dull b Date: Mon, 24 Jul 2023 04:12:27 +0000 Subject: [PATCH] Attempt default Crud::create --- crates/db_schema/src/traits.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/db_schema/src/traits.rs b/crates/db_schema/src/traits.rs index 61a067671..3e1ee2207 100644 --- a/crates/db_schema/src/traits.rs +++ b/crates/db_schema/src/traits.rs @@ -29,14 +29,18 @@ LimitDsl + Send + Sized + 'static, pub trait Crud where Self: HasTable + Sized, - Self::Table: FindDsl, + Self::Table: FindDsl + 'static, dsl::Find: LimitDsl + Send, - for<'query> dsl::Limit>: - Send + LoadQuery<'query, AsyncPgConnection, Self> + 'query, + 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> &'a Self::InsertForm: Insertable, + for<'a> InsertStatement>::Values>: + LoadQuery<'a, AsyncPgConnection, Self> + 'a, + for<'a> <&'a Self::InsertForm as Insertable>::Values: 'a,*/ type InsertForm; type UpdateForm; type IdType: Hash @@ -46,11 +50,9 @@ where + AsExpression<<::PrimaryKey as Expression>::SqlType>; async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result; /*{ - let conn = &mut get_conn(pool).await?; - insert_into(Self::table()) - .values(form) - .get_result::(conn) - .await + 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 { let query = Self::table().find(id);