lemmy/crates/db_schema/src/impls/secret.rs

21 lines
520 B
Rust
Raw Normal View History

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