]> Untitled Git - lemmy.git/blobdiff - crates/db_schema/src/impls/secret.rs
Make functions work with both connection and pool (#3420)
[lemmy.git] / crates / db_schema / src / impls / secret.rs
index 1f92ee24008b2d01131ea77122aa4339e5747c99..f21c6c48735ce1083005ee2d379dcb1aa384a798 100644 (file)
@@ -1,15 +1,20 @@
-use crate::source::secret::Secret;
-use diesel::{result::Error, *};
+use crate::{
+  schema::secret::dsl::secret,
+  source::secret::Secret,
+  utils::{get_conn, DbPool},
+};
+use diesel::result::Error;
+use diesel_async::RunQueryDsl;
 
 impl Secret {
   /// Initialize the Secrets from the DB.
   /// Warning: You should only call this once.
-  pub fn init(conn: &mut PgConnection) -> Result<Secret, Error> {
-    read_secrets(conn)
+  pub async fn init(pool: &mut DbPool<'_>) -> Result<Secret, Error> {
+    Self::read_secrets(pool).await
   }
-}
 
-fn read_secrets(conn: &mut PgConnection) -> Result<Secret, Error> {
-  use crate::schema::secret::dsl::*;
-  secret.first::<Secret>(conn)
+  async fn read_secrets(pool: &mut DbPool<'_>) -> Result<Secret, Error> {
+    let conn = &mut get_conn(pool).await?;
+    secret.first::<Secret>(conn).await
+  }
 }