lemmy/crates/db_schema/src/impls/secret.rs
2023-07-05 06:33:53 +00:00

21 lines
549 B
Rust

use crate::{
schema::secret::dsl::secret,
source::secret::Secret,
utils::{DbPool, GetConn},
};
use diesel::result::Error;
use diesel_async::RunQueryDsl;
impl Secret {
/// Initialize the Secrets from the DB.
/// Warning: You should only call this once.
pub async fn init(mut pool: &mut impl GetConn) -> Result<Secret, Error> {
Self::read_secrets(pool).await
}
async fn read_secrets(mut pool: &mut impl GetConn) -> Result<Secret, Error> {
let conn = &mut *pool.get_conn().await?;
secret.first::<Secret>(conn).await
}
}