X-Git-Url: http://these/git/?a=blobdiff_plain;f=crates%2Fdb_schema%2Fsrc%2Fimpls%2Fperson_mention.rs;h=27c04217e0f1e0e42871fe9535471d695986f935;hb=92568956353f21649ed9aff68b42699c9d036f30;hp=d902e951df46510de47ad0989a9e722250a962f7;hpb=5d837780f5d149cb8d3b861c63a7dc4466a7cbf1;p=lemmy.git diff --git a/crates/db_schema/src/impls/person_mention.rs b/crates/db_schema/src/impls/person_mention.rs index d902e951..27c04217 100644 --- a/crates/db_schema/src/impls/person_mention.rs +++ b/crates/db_schema/src/impls/person_mention.rs @@ -1,11 +1,11 @@ use crate::{ newtypes::{CommentId, PersonId, PersonMentionId}, - schema::person_mention::dsl::*, - source::person_mention::*, + schema::person_mention::dsl::{comment_id, person_mention, read, recipient_id}, + source::person_mention::{PersonMention, PersonMentionInsertForm, PersonMentionUpdateForm}, traits::Crud, utils::{get_conn, DbPool}, }; -use diesel::{dsl::*, result::Error, *}; +use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; #[async_trait] @@ -13,7 +13,7 @@ impl Crud for PersonMention { type InsertForm = PersonMentionInsertForm; type UpdateForm = PersonMentionUpdateForm; type IdType = PersonMentionId; - async fn read(pool: &DbPool, person_mention_id: PersonMentionId) -> Result { + async fn read(pool: &mut DbPool<'_>, person_mention_id: PersonMentionId) -> Result { let conn = &mut get_conn(pool).await?; person_mention .find(person_mention_id) @@ -21,7 +21,10 @@ impl Crud for PersonMention { .await } - async fn create(pool: &DbPool, person_mention_form: &Self::InsertForm) -> Result { + async fn create( + pool: &mut DbPool<'_>, + person_mention_form: &Self::InsertForm, + ) -> Result { let conn = &mut get_conn(pool).await?; // since the return here isnt utilized, we dont need to do an update // but get_result doesnt return the existing row here @@ -35,7 +38,7 @@ impl Crud for PersonMention { } async fn update( - pool: &DbPool, + pool: &mut DbPool<'_>, person_mention_id: PersonMentionId, person_mention_form: &Self::UpdateForm, ) -> Result { @@ -49,7 +52,7 @@ impl Crud for PersonMention { impl PersonMention { pub async fn mark_all_as_read( - pool: &DbPool, + pool: &mut DbPool<'_>, for_recipient_id: PersonId, ) -> Result, Error> { let conn = &mut get_conn(pool).await?; @@ -64,7 +67,7 @@ impl PersonMention { } pub async fn read_by_comment_and_person( - pool: &DbPool, + pool: &mut DbPool<'_>, for_comment_id: CommentId, for_recipient_id: PersonId, ) -> Result { @@ -79,14 +82,17 @@ impl PersonMention { #[cfg(test)] mod tests { + #![allow(clippy::unwrap_used)] + #![allow(clippy::indexing_slicing)] + use crate::{ source::{ - comment::*, + comment::{Comment, CommentInsertForm}, community::{Community, CommunityInsertForm}, instance::Instance, - person::*, - person_mention::*, - post::*, + person::{Person, PersonInsertForm}, + person_mention::{PersonMention, PersonMentionInsertForm, PersonMentionUpdateForm}, + post::{Post, PostInsertForm}, }, traits::Crud, utils::build_db_pool_for_tests, @@ -97,8 +103,11 @@ mod tests { #[serial] async fn test_crud() { let pool = &build_db_pool_for_tests().await; + let pool = &mut pool.into(); - let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap(); + let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()) + .await + .unwrap(); let new_person = PersonInsertForm::builder() .name("terrylake".into())