]> Untitled Git - lemmy.git/blobdiff - crates/db_schema/src/aggregates/community_aggregates.rs
Make functions work with both connection and pool (#3420)
[lemmy.git] / crates / db_schema / src / aggregates / community_aggregates.rs
index 96dbb8fb4d2440a45178209a20e164e79100aa94..61abd193c6b1ce427762cb85a1410a1d1772cb04 100644 (file)
@@ -8,7 +8,7 @@ use diesel::{result::Error, ExpressionMethods, QueryDsl};
 use diesel_async::RunQueryDsl;
 
 impl CommunityAggregates {
-  pub async fn read(pool: &DbPool, community_id: CommunityId) -> Result<Self, Error> {
+  pub async fn read(pool: &mut DbPool<'_>, community_id: CommunityId) -> Result<Self, Error> {
     let conn = &mut get_conn(pool).await?;
     community_aggregates::table
       .filter(community_aggregates::community_id.eq(community_id))
@@ -37,8 +37,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("thommy_community_agg".into())
@@ -165,7 +168,7 @@ mod tests {
       .unwrap();
     assert_eq!(2, after_follow_again.subscribers);
 
-    // Remove a parent comment (the comment count should also be 0)
+    // Remove a parent post (the comment count should also be 0)
     Post::delete(pool, inserted_post.id).await.unwrap();
     let after_parent_post_delete = CommunityAggregates::read(pool, inserted_community.id)
       .await