]> Untitled Git - lemmy.git/blobdiff - crates/db_schema/src/impls/tagline.rs
Make functions work with both connection and pool (#3420)
[lemmy.git] / crates / db_schema / src / impls / tagline.rs
index 3696ac5779d80dd0d2cc27411db81ca421a85866..be4860e17fd95c105c05a757c81b723d228e26fa 100644 (file)
@@ -1,7 +1,7 @@
 use crate::{
   newtypes::LocalSiteId,
-  schema::tagline::dsl::*,
-  source::tagline::*,
+  schema::tagline::dsl::{local_site_id, tagline},
+  source::tagline::{Tagline, TaglineForm},
   utils::{get_conn, DbPool},
 };
 use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
@@ -9,12 +9,12 @@ use diesel_async::{AsyncPgConnection, RunQueryDsl};
 
 impl Tagline {
   pub async fn replace(
-    pool: &DbPool,
+    pool: &mut DbPool<'_>,
     for_local_site_id: LocalSiteId,
     list_content: Option<Vec<String>>,
-  ) -> Result<(), Error> {
+  ) -> Result<Vec<Self>, Error> {
+    let conn = &mut get_conn(pool).await?;
     if let Some(list) = list_content {
-      let conn = &mut get_conn(pool).await?;
       conn
         .build_transaction()
         .run(|conn| {
@@ -32,20 +32,23 @@ impl Tagline {
                 .get_result::<Self>(conn)
                 .await?;
             }
-            Ok(())
+            Self::get_all(&mut conn.into(), for_local_site_id).await
           }) as _
         })
         .await
     } else {
-      Ok(())
+      Self::get_all(&mut conn.into(), for_local_site_id).await
     }
   }
 
   async fn clear(conn: &mut AsyncPgConnection) -> Result<usize, Error> {
     diesel::delete(tagline).execute(conn).await
   }
-  pub async fn get_all(pool: &DbPool, for_local_site_id: LocalSiteId) -> Result<Vec<Self>, Error> {
-    use crate::schema::tagline::dsl::*;
+
+  pub async fn get_all(
+    pool: &mut DbPool<'_>,
+    for_local_site_id: LocalSiteId,
+  ) -> Result<Vec<Self>, Error> {
     let conn = &mut get_conn(pool).await?;
     tagline
       .filter(local_site_id.eq(for_local_site_id))