From 7ed20f5f713600bd48c85aad0848d8dbaae56503 Mon Sep 17 00:00:00 2001 From: dull b Date: Mon, 24 Jul 2023 04:21:06 +0000 Subject: [PATCH] Change Crud to Crud<'a> (won't compile) --- crates/db_schema/src/impls/comment.rs | 9 +- crates/db_schema/src/impls/comment_reply.rs | 6 +- crates/db_schema/src/impls/community.rs | 6 +- crates/db_schema/src/impls/local_user.rs | 6 +- crates/db_schema/src/impls/moderator.rs | 101 ++++++++++-------- .../src/impls/password_reset_request.rs | 9 +- crates/db_schema/src/impls/person.rs | 6 +- crates/db_schema/src/impls/person_mention.rs | 6 +- crates/db_schema/src/impls/post.rs | 6 +- crates/db_schema/src/impls/private_message.rs | 6 +- .../src/impls/registration_application.rs | 6 +- crates/db_schema/src/impls/site.rs | 6 +- crates/db_schema/src/traits.rs | 10 +- 13 files changed, 100 insertions(+), 83 deletions(-) diff --git a/crates/db_schema/src/impls/comment.rs b/crates/db_schema/src/impls/comment.rs index d6d2ab949..a9ab91b3c 100644 --- a/crates/db_schema/src/impls/comment.rs +++ b/crates/db_schema/src/impls/comment.rs @@ -152,7 +152,7 @@ where ca.comment_id = c.id" } #[async_trait] -impl Crud for Comment { +impl<'a> Crud<'a> for Comment { type InsertForm = CommentInsertForm; type UpdateForm = CommentUpdateForm; type IdType = CommentId; @@ -163,14 +163,17 @@ impl Crud for Comment { } /// This is unimplemented, use [[Comment::create]] - async fn create(_pool: &mut DbPool<'_>, _comment_form: &Self::InsertForm) -> Result { + async fn create( + _pool: &mut DbPool<'_>, + _comment_form: &'a Self::InsertForm, + ) -> Result { unimplemented!(); } async fn update( pool: &mut DbPool<'_>, comment_id: CommentId, - comment_form: &Self::UpdateForm, + comment_form: &'a Self::UpdateForm, ) -> Result { let conn = &mut get_conn(pool).await?; diesel::update(comment.find(comment_id)) diff --git a/crates/db_schema/src/impls/comment_reply.rs b/crates/db_schema/src/impls/comment_reply.rs index c5b5a3c6a..a7c5d5159 100644 --- a/crates/db_schema/src/impls/comment_reply.rs +++ b/crates/db_schema/src/impls/comment_reply.rs @@ -9,14 +9,14 @@ use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; #[async_trait] -impl Crud for CommentReply { +impl<'a> Crud<'a> for CommentReply { type InsertForm = CommentReplyInsertForm; type UpdateForm = CommentReplyUpdateForm; type IdType = CommentReplyId; async fn create( pool: &mut DbPool<'_>, - comment_reply_form: &Self::InsertForm, + comment_reply_form: &'a Self::InsertForm, ) -> Result { let conn = &mut get_conn(pool).await?; @@ -34,7 +34,7 @@ impl Crud for CommentReply { async fn update( pool: &mut DbPool<'_>, comment_reply_id: CommentReplyId, - comment_reply_form: &Self::UpdateForm, + comment_reply_form: &'a Self::UpdateForm, ) -> Result { let conn = &mut get_conn(pool).await?; diesel::update(comment_reply.find(comment_reply_id)) diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index d76770203..f37b35ca6 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -23,7 +23,7 @@ use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; #[async_trait] -impl Crud for Community { +impl<'a> Crud<'a> for Community { type InsertForm = CommunityInsertForm; type UpdateForm = CommunityUpdateForm; type IdType = CommunityId; @@ -35,7 +35,7 @@ impl Crud for Community { .await } - async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result { let is_new_community = match &form.actor_id { Some(id) => Community::read_from_apub_id(pool, id).await?.is_none(), None => true, @@ -62,7 +62,7 @@ impl Crud for Community { async fn update( pool: &mut DbPool<'_>, community_id: CommunityId, - form: &Self::UpdateForm, + form: &'a Self::UpdateForm, ) -> Result { let conn = &mut get_conn(pool).await?; diesel::update(community::table.find(community_id)) diff --git a/crates/db_schema/src/impls/local_user.rs b/crates/db_schema/src/impls/local_user.rs index ba882297c..d5caa7573 100644 --- a/crates/db_schema/src/impls/local_user.rs +++ b/crates/db_schema/src/impls/local_user.rs @@ -65,7 +65,7 @@ impl LocalUser { } #[async_trait] -impl Crud for LocalUser { +impl<'a> Crud<'a> for LocalUser { type InsertForm = LocalUserInsertForm; type UpdateForm = LocalUserUpdateForm; type IdType = LocalUserId; @@ -76,7 +76,7 @@ impl Crud for LocalUser { .execute(conn) .await } - async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result { let conn = &mut get_conn(pool).await?; let mut form_with_encrypted_password = form.clone(); let password_hash = @@ -103,7 +103,7 @@ impl Crud for LocalUser { async fn update( pool: &mut DbPool<'_>, local_user_id: LocalUserId, - form: &Self::UpdateForm, + form: &'a Self::UpdateForm, ) -> Result { let conn = &mut get_conn(pool).await?; diesel::update(local_user.find(local_user_id)) diff --git a/crates/db_schema/src/impls/moderator.rs b/crates/db_schema/src/impls/moderator.rs index a4c300b2a..46cf97d8a 100644 --- a/crates/db_schema/src/impls/moderator.rs +++ b/crates/db_schema/src/impls/moderator.rs @@ -38,12 +38,12 @@ use diesel::{dsl::insert_into, result::Error, QueryDsl}; use diesel_async::RunQueryDsl; #[async_trait] -impl Crud for ModRemovePost { +impl<'a> Crud<'a> for ModRemovePost { type InsertForm = ModRemovePostForm; type UpdateForm = ModRemovePostForm; type IdType = i32; - async fn create(pool: &mut DbPool<'_>, form: &ModRemovePostForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a ModRemovePostForm) -> Result { use crate::schema::mod_remove_post::dsl::mod_remove_post; let conn = &mut get_conn(pool).await?; insert_into(mod_remove_post) @@ -55,7 +55,7 @@ impl Crud for ModRemovePost { async fn update( pool: &mut DbPool<'_>, from_id: i32, - form: &ModRemovePostForm, + form: &'a ModRemovePostForm, ) -> Result { use crate::schema::mod_remove_post::dsl::mod_remove_post; let conn = &mut get_conn(pool).await?; @@ -67,12 +67,12 @@ impl Crud for ModRemovePost { } #[async_trait] -impl Crud for ModLockPost { +impl<'a> Crud<'a> for ModLockPost { type InsertForm = ModLockPostForm; type UpdateForm = ModLockPostForm; type IdType = i32; - async fn create(pool: &mut DbPool<'_>, form: &ModLockPostForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a ModLockPostForm) -> Result { use crate::schema::mod_lock_post::dsl::mod_lock_post; let conn = &mut get_conn(pool).await?; insert_into(mod_lock_post) @@ -84,7 +84,7 @@ impl Crud for ModLockPost { async fn update( pool: &mut DbPool<'_>, from_id: i32, - form: &ModLockPostForm, + form: &'a ModLockPostForm, ) -> Result { use crate::schema::mod_lock_post::dsl::mod_lock_post; let conn = &mut get_conn(pool).await?; @@ -96,12 +96,12 @@ impl Crud for ModLockPost { } #[async_trait] -impl Crud for ModFeaturePost { +impl<'a> Crud<'a> for ModFeaturePost { type InsertForm = ModFeaturePostForm; type UpdateForm = ModFeaturePostForm; type IdType = i32; - async fn create(pool: &mut DbPool<'_>, form: &ModFeaturePostForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a ModFeaturePostForm) -> Result { use crate::schema::mod_feature_post::dsl::mod_feature_post; let conn = &mut get_conn(pool).await?; insert_into(mod_feature_post) @@ -113,7 +113,7 @@ impl Crud for ModFeaturePost { async fn update( pool: &mut DbPool<'_>, from_id: i32, - form: &ModFeaturePostForm, + form: &'a ModFeaturePostForm, ) -> Result { use crate::schema::mod_feature_post::dsl::mod_feature_post; let conn = &mut get_conn(pool).await?; @@ -125,12 +125,12 @@ impl Crud for ModFeaturePost { } #[async_trait] -impl Crud for ModRemoveComment { +impl<'a> Crud<'a> for ModRemoveComment { type InsertForm = ModRemoveCommentForm; type UpdateForm = ModRemoveCommentForm; type IdType = i32; - async fn create(pool: &mut DbPool<'_>, form: &ModRemoveCommentForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a ModRemoveCommentForm) -> Result { use crate::schema::mod_remove_comment::dsl::mod_remove_comment; let conn = &mut get_conn(pool).await?; insert_into(mod_remove_comment) @@ -142,7 +142,7 @@ impl Crud for ModRemoveComment { async fn update( pool: &mut DbPool<'_>, from_id: i32, - form: &ModRemoveCommentForm, + form: &'a ModRemoveCommentForm, ) -> Result { use crate::schema::mod_remove_comment::dsl::mod_remove_comment; let conn = &mut get_conn(pool).await?; @@ -154,12 +154,12 @@ impl Crud for ModRemoveComment { } #[async_trait] -impl Crud for ModRemoveCommunity { +impl<'a> Crud<'a> for ModRemoveCommunity { type InsertForm = ModRemoveCommunityForm; type UpdateForm = ModRemoveCommunityForm; type IdType = i32; - async fn create(pool: &mut DbPool<'_>, form: &ModRemoveCommunityForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a ModRemoveCommunityForm) -> Result { use crate::schema::mod_remove_community::dsl::mod_remove_community; let conn = &mut get_conn(pool).await?; insert_into(mod_remove_community) @@ -171,7 +171,7 @@ impl Crud for ModRemoveCommunity { async fn update( pool: &mut DbPool<'_>, from_id: i32, - form: &ModRemoveCommunityForm, + form: &'a ModRemoveCommunityForm, ) -> Result { use crate::schema::mod_remove_community::dsl::mod_remove_community; let conn = &mut get_conn(pool).await?; @@ -183,12 +183,12 @@ impl Crud for ModRemoveCommunity { } #[async_trait] -impl Crud for ModBanFromCommunity { +impl<'a> Crud<'a> for ModBanFromCommunity { type InsertForm = ModBanFromCommunityForm; type UpdateForm = ModBanFromCommunityForm; type IdType = i32; - async fn create(pool: &mut DbPool<'_>, form: &ModBanFromCommunityForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a ModBanFromCommunityForm) -> Result { use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community; let conn = &mut get_conn(pool).await?; insert_into(mod_ban_from_community) @@ -200,7 +200,7 @@ impl Crud for ModBanFromCommunity { async fn update( pool: &mut DbPool<'_>, from_id: i32, - form: &ModBanFromCommunityForm, + form: &'a ModBanFromCommunityForm, ) -> Result { use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community; let conn = &mut get_conn(pool).await?; @@ -212,12 +212,12 @@ impl Crud for ModBanFromCommunity { } #[async_trait] -impl Crud for ModBan { +impl<'a> Crud<'a> for ModBan { type InsertForm = ModBanForm; type UpdateForm = ModBanForm; type IdType = i32; - async fn create(pool: &mut DbPool<'_>, form: &ModBanForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a ModBanForm) -> Result { use crate::schema::mod_ban::dsl::mod_ban; let conn = &mut get_conn(pool).await?; insert_into(mod_ban) @@ -226,7 +226,11 @@ impl Crud for ModBan { .await } - async fn update(pool: &mut DbPool<'_>, from_id: i32, form: &ModBanForm) -> Result { + async fn update( + pool: &mut DbPool<'_>, + from_id: i32, + form: &'a ModBanForm, + ) -> Result { use crate::schema::mod_ban::dsl::mod_ban; let conn = &mut get_conn(pool).await?; diesel::update(mod_ban.find(from_id)) @@ -237,12 +241,12 @@ impl Crud for ModBan { } #[async_trait] -impl Crud for ModHideCommunity { +impl<'a> Crud<'a> for ModHideCommunity { type InsertForm = ModHideCommunityForm; type UpdateForm = ModHideCommunityForm; type IdType = i32; - async fn create(pool: &mut DbPool<'_>, form: &ModHideCommunityForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a ModHideCommunityForm) -> Result { use crate::schema::mod_hide_community::dsl::mod_hide_community; let conn = &mut get_conn(pool).await?; insert_into(mod_hide_community) @@ -254,7 +258,7 @@ impl Crud for ModHideCommunity { async fn update( pool: &mut DbPool<'_>, from_id: i32, - form: &ModHideCommunityForm, + form: &'a ModHideCommunityForm, ) -> Result { use crate::schema::mod_hide_community::dsl::mod_hide_community; let conn = &mut get_conn(pool).await?; @@ -266,12 +270,12 @@ impl Crud for ModHideCommunity { } #[async_trait] -impl Crud for ModAddCommunity { +impl<'a> Crud<'a> for ModAddCommunity { type InsertForm = ModAddCommunityForm; type UpdateForm = ModAddCommunityForm; type IdType = i32; - async fn create(pool: &mut DbPool<'_>, form: &ModAddCommunityForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a ModAddCommunityForm) -> Result { use crate::schema::mod_add_community::dsl::mod_add_community; let conn = &mut get_conn(pool).await?; insert_into(mod_add_community) @@ -283,7 +287,7 @@ impl Crud for ModAddCommunity { async fn update( pool: &mut DbPool<'_>, from_id: i32, - form: &ModAddCommunityForm, + form: &'a ModAddCommunityForm, ) -> Result { use crate::schema::mod_add_community::dsl::mod_add_community; let conn = &mut get_conn(pool).await?; @@ -295,12 +299,15 @@ impl Crud for ModAddCommunity { } #[async_trait] -impl Crud for ModTransferCommunity { +impl<'a> Crud<'a> for ModTransferCommunity { type InsertForm = ModTransferCommunityForm; type UpdateForm = ModTransferCommunityForm; type IdType = i32; - async fn create(pool: &mut DbPool<'_>, form: &ModTransferCommunityForm) -> Result { + async fn create( + pool: &mut DbPool<'_>, + form: &'a ModTransferCommunityForm, + ) -> Result { use crate::schema::mod_transfer_community::dsl::mod_transfer_community; let conn = &mut get_conn(pool).await?; insert_into(mod_transfer_community) @@ -312,7 +319,7 @@ impl Crud for ModTransferCommunity { async fn update( pool: &mut DbPool<'_>, from_id: i32, - form: &ModTransferCommunityForm, + form: &'a ModTransferCommunityForm, ) -> Result { use crate::schema::mod_transfer_community::dsl::mod_transfer_community; let conn = &mut get_conn(pool).await?; @@ -324,12 +331,12 @@ impl Crud for ModTransferCommunity { } #[async_trait] -impl Crud for ModAdd { +impl<'a> Crud<'a> for ModAdd { type InsertForm = ModAddForm; type UpdateForm = ModAddForm; type IdType = i32; - async fn create(pool: &mut DbPool<'_>, form: &ModAddForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a ModAddForm) -> Result { use crate::schema::mod_add::dsl::mod_add; let conn = &mut get_conn(pool).await?; insert_into(mod_add) @@ -338,7 +345,11 @@ impl Crud for ModAdd { .await } - async fn update(pool: &mut DbPool<'_>, from_id: i32, form: &ModAddForm) -> Result { + async fn update( + pool: &mut DbPool<'_>, + from_id: i32, + form: &'a ModAddForm, + ) -> Result { use crate::schema::mod_add::dsl::mod_add; let conn = &mut get_conn(pool).await?; diesel::update(mod_add.find(from_id)) @@ -349,12 +360,12 @@ impl Crud for ModAdd { } #[async_trait] -impl Crud for AdminPurgePerson { +impl<'a> Crud<'a> for AdminPurgePerson { type InsertForm = AdminPurgePersonForm; type UpdateForm = AdminPurgePersonForm; type IdType = i32; - async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result { use crate::schema::admin_purge_person::dsl::admin_purge_person; let conn = &mut get_conn(pool).await?; insert_into(admin_purge_person) @@ -366,7 +377,7 @@ impl Crud for AdminPurgePerson { async fn update( pool: &mut DbPool<'_>, from_id: i32, - form: &Self::InsertForm, + form: &'a Self::InsertForm, ) -> Result { use crate::schema::admin_purge_person::dsl::admin_purge_person; let conn = &mut get_conn(pool).await?; @@ -378,12 +389,12 @@ impl Crud for AdminPurgePerson { } #[async_trait] -impl Crud for AdminPurgeCommunity { +impl<'a> Crud<'a> for AdminPurgeCommunity { type InsertForm = AdminPurgeCommunityForm; type UpdateForm = AdminPurgeCommunityForm; type IdType = i32; - async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result { use crate::schema::admin_purge_community::dsl::admin_purge_community; let conn = &mut get_conn(pool).await?; insert_into(admin_purge_community) @@ -395,7 +406,7 @@ impl Crud for AdminPurgeCommunity { async fn update( pool: &mut DbPool<'_>, from_id: i32, - form: &Self::InsertForm, + form: &'a Self::InsertForm, ) -> Result { use crate::schema::admin_purge_community::dsl::admin_purge_community; let conn = &mut get_conn(pool).await?; @@ -407,12 +418,12 @@ impl Crud for AdminPurgeCommunity { } #[async_trait] -impl Crud for AdminPurgePost { +impl<'a> Crud<'a> for AdminPurgePost { type InsertForm = AdminPurgePostForm; type UpdateForm = AdminPurgePostForm; type IdType = i32; - async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result { use crate::schema::admin_purge_post::dsl::admin_purge_post; let conn = &mut get_conn(pool).await?; insert_into(admin_purge_post) @@ -424,7 +435,7 @@ impl Crud for AdminPurgePost { async fn update( pool: &mut DbPool<'_>, from_id: i32, - form: &Self::InsertForm, + form: &'a Self::InsertForm, ) -> Result { use crate::schema::admin_purge_post::dsl::admin_purge_post; let conn = &mut get_conn(pool).await?; @@ -436,12 +447,12 @@ impl Crud for AdminPurgePost { } #[async_trait] -impl Crud for AdminPurgeComment { +impl<'a> Crud<'a> for AdminPurgeComment { type InsertForm = AdminPurgeCommentForm; type UpdateForm = AdminPurgeCommentForm; type IdType = i32; - async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result { use crate::schema::admin_purge_comment::dsl::admin_purge_comment; let conn = &mut get_conn(pool).await?; insert_into(admin_purge_comment) @@ -453,7 +464,7 @@ impl Crud for AdminPurgeComment { async fn update( pool: &mut DbPool<'_>, from_id: i32, - form: &Self::InsertForm, + form: &'a Self::InsertForm, ) -> Result { use crate::schema::admin_purge_comment::dsl::admin_purge_comment; let conn = &mut get_conn(pool).await?; diff --git a/crates/db_schema/src/impls/password_reset_request.rs b/crates/db_schema/src/impls/password_reset_request.rs index 9daaa1664..54b914b2a 100644 --- a/crates/db_schema/src/impls/password_reset_request.rs +++ b/crates/db_schema/src/impls/password_reset_request.rs @@ -20,12 +20,15 @@ use diesel_async::RunQueryDsl; use sha2::{Digest, Sha256}; #[async_trait] -impl Crud for PasswordResetRequest { +impl<'a> Crud<'a> for PasswordResetRequest { type InsertForm = PasswordResetRequestForm; type UpdateForm = PasswordResetRequestForm; type IdType = i32; - async fn create(pool: &mut DbPool<'_>, form: &PasswordResetRequestForm) -> Result { + async fn create( + pool: &mut DbPool<'_>, + form: &'a PasswordResetRequestForm, + ) -> Result { let conn = &mut get_conn(pool).await?; insert_into(password_reset_request) .values(form) @@ -35,7 +38,7 @@ impl Crud for PasswordResetRequest { async fn update( pool: &mut DbPool<'_>, password_reset_request_id: i32, - form: &PasswordResetRequestForm, + form: &'a PasswordResetRequestForm, ) -> Result { let conn = &mut get_conn(pool).await?; diesel::update(password_reset_request.find(password_reset_request_id)) diff --git a/crates/db_schema/src/impls/person.rs b/crates/db_schema/src/impls/person.rs index c06c1c728..16a0ca321 100644 --- a/crates/db_schema/src/impls/person.rs +++ b/crates/db_schema/src/impls/person.rs @@ -15,7 +15,7 @@ use diesel::{dsl::insert_into, result::Error, ExpressionMethods, JoinOnDsl, Quer use diesel_async::RunQueryDsl; #[async_trait] -impl Crud for Person { +impl<'a> Crud<'a> for Person { type InsertForm = PersonInsertForm; type UpdateForm = PersonUpdateForm; type IdType = PersonId; @@ -34,7 +34,7 @@ impl Crud for Person { .execute(conn) .await } - async fn create(pool: &mut DbPool<'_>, form: &PersonInsertForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a PersonInsertForm) -> Result { let conn = &mut get_conn(pool).await?; insert_into(person::table) .values(form) @@ -44,7 +44,7 @@ impl Crud for Person { async fn update( pool: &mut DbPool<'_>, person_id: PersonId, - form: &PersonUpdateForm, + form: &'a PersonUpdateForm, ) -> Result { let conn = &mut get_conn(pool).await?; diesel::update(person::table.find(person_id)) diff --git a/crates/db_schema/src/impls/person_mention.rs b/crates/db_schema/src/impls/person_mention.rs index f2441f00c..980549a38 100644 --- a/crates/db_schema/src/impls/person_mention.rs +++ b/crates/db_schema/src/impls/person_mention.rs @@ -9,14 +9,14 @@ use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; #[async_trait] -impl Crud for PersonMention { +impl<'a> Crud<'a> for PersonMention { type InsertForm = PersonMentionInsertForm; type UpdateForm = PersonMentionUpdateForm; type IdType = PersonMentionId; async fn create( pool: &mut DbPool<'_>, - person_mention_form: &Self::InsertForm, + person_mention_form: &'a Self::InsertForm, ) -> Result { let conn = &mut get_conn(pool).await?; // since the return here isnt utilized, we dont need to do an update @@ -33,7 +33,7 @@ impl Crud for PersonMention { async fn update( pool: &mut DbPool<'_>, person_mention_id: PersonMentionId, - person_mention_form: &Self::UpdateForm, + person_mention_form: &'a Self::UpdateForm, ) -> Result { let conn = &mut get_conn(pool).await?; diesel::update(person_mention.find(person_mention_id)) diff --git a/crates/db_schema/src/impls/post.rs b/crates/db_schema/src/impls/post.rs index 9e05786b2..db7f4589b 100644 --- a/crates/db_schema/src/impls/post.rs +++ b/crates/db_schema/src/impls/post.rs @@ -34,7 +34,7 @@ use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl, TextE use diesel_async::RunQueryDsl; #[async_trait] -impl Crud for Post { +impl<'a> Crud<'a> for Post { type InsertForm = PostInsertForm; type UpdateForm = PostUpdateForm; type IdType = PostId; @@ -44,7 +44,7 @@ impl Crud for Post { diesel::delete(post.find(post_id)).execute(conn).await } - async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result { let conn = &mut get_conn(pool).await?; insert_into(post) .values(form) @@ -58,7 +58,7 @@ impl Crud for Post { async fn update( pool: &mut DbPool<'_>, post_id: PostId, - new_post: &Self::UpdateForm, + new_post: &'a Self::UpdateForm, ) -> Result { let conn = &mut get_conn(pool).await?; diesel::update(post.find(post_id)) diff --git a/crates/db_schema/src/impls/private_message.rs b/crates/db_schema/src/impls/private_message.rs index 7c6ec4673..62bf11def 100644 --- a/crates/db_schema/src/impls/private_message.rs +++ b/crates/db_schema/src/impls/private_message.rs @@ -11,12 +11,12 @@ use lemmy_utils::error::LemmyError; use url::Url; #[async_trait] -impl Crud for PrivateMessage { +impl<'a> Crud<'a> for PrivateMessage { type InsertForm = PrivateMessageInsertForm; type UpdateForm = PrivateMessageUpdateForm; type IdType = PrivateMessageId; - async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result { let conn = &mut get_conn(pool).await?; insert_into(private_message) .values(form) @@ -30,7 +30,7 @@ impl Crud for PrivateMessage { async fn update( pool: &mut DbPool<'_>, private_message_id: PrivateMessageId, - form: &Self::UpdateForm, + form: &'a Self::UpdateForm, ) -> Result { let conn = &mut get_conn(pool).await?; diesel::update(private_message.find(private_message_id)) diff --git a/crates/db_schema/src/impls/registration_application.rs b/crates/db_schema/src/impls/registration_application.rs index 5dd6b8e1e..20023481c 100644 --- a/crates/db_schema/src/impls/registration_application.rs +++ b/crates/db_schema/src/impls/registration_application.rs @@ -13,12 +13,12 @@ use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; #[async_trait] -impl Crud for RegistrationApplication { +impl<'a> Crud<'a> for RegistrationApplication { type InsertForm = RegistrationApplicationInsertForm; type UpdateForm = RegistrationApplicationUpdateForm; type IdType = i32; - async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result { let conn = &mut get_conn(pool).await?; insert_into(registration_application) .values(form) @@ -29,7 +29,7 @@ impl Crud for RegistrationApplication { async fn update( pool: &mut DbPool<'_>, id_: Self::IdType, - form: &Self::UpdateForm, + form: &'a Self::UpdateForm, ) -> Result { let conn = &mut get_conn(pool).await?; diesel::update(registration_application.find(id_)) diff --git a/crates/db_schema/src/impls/site.rs b/crates/db_schema/src/impls/site.rs index 6e2cca2a7..f143e5630 100644 --- a/crates/db_schema/src/impls/site.rs +++ b/crates/db_schema/src/impls/site.rs @@ -13,7 +13,7 @@ use diesel_async::RunQueryDsl; use url::Url; #[async_trait] -impl Crud for Site { +impl<'a> Crud<'a> for Site { type InsertForm = SiteInsertForm; type UpdateForm = SiteUpdateForm; type IdType = SiteId; @@ -37,7 +37,7 @@ impl Crud for Site { unimplemented!() }*/ - async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result { + async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result { let is_new_site = match &form.actor_id { Some(id_) => Site::read_from_apub_id(pool, id_).await?.is_none(), None => true, @@ -64,7 +64,7 @@ impl Crud for Site { async fn update( pool: &mut DbPool<'_>, site_id: SiteId, - new_site: &Self::UpdateForm, + new_site: &'a Self::UpdateForm, ) -> Result { let conn = &mut get_conn(pool).await?; diesel::update(site.find(site_id)) diff --git a/crates/db_schema/src/traits.rs b/crates/db_schema/src/traits.rs index 3e1ee2207..92ea4d195 100644 --- a/crates/db_schema/src/traits.rs +++ b/crates/db_schema/src/traits.rs @@ -26,13 +26,13 @@ LimitDsl + Send + Sized + 'static, <::PrimaryKey as Expression>::SqlType: SqlType, ::PrimaryKey: ExpressionMethods + Send + Sized + 'static,*/ #[async_trait] -pub trait Crud +pub trait Crud<'a> where Self: HasTable + Sized, Self::Table: FindDsl + 'static, dsl::Find: LimitDsl + Send, - for<'a> dsl::Limit>: - Send + LoadQuery<'a, AsyncPgConnection, Self> + 'a, + for<'query> dsl::Limit>: + Send + LoadQuery<'query, AsyncPgConnection, Self> + 'query, <::Table as Table>::PrimaryKey: ExpressionMethods + Send, <<::Table as Table>::PrimaryKey as Expression>::SqlType: SqlType + TypedExpressionType, @@ -48,7 +48,7 @@ where + Sized + Send + AsExpression<<::PrimaryKey as Expression>::SqlType>; - async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result; + async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result; /*{ let query = insert_into(Self::table()).values(form); let conn = &mut *get_conn(pool).await?; @@ -63,7 +63,7 @@ where async fn update( pool: &mut DbPool<'_>, id: Self::IdType, - form: &Self::UpdateForm, + form: &'a Self::UpdateForm, ) -> Result; /*{ let conn = &mut get_conn(pool).await?;