d075acce43
- Diesel ordinarily throws an error when no results are returned for a single fetch, which is a bit confusing. This PR ensures that the missing value cases are all caught, and wrapped with new LemmyErrors, rather than diesel errors. - Fixes #4601
21 lines
580 B
Rust
21 lines
580 B
Rust
use crate::{
|
|
diesel::OptionalExtension,
|
|
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 async fn init(pool: &mut DbPool<'_>) -> Result<Option<Secret>, Error> {
|
|
Self::read_secrets(pool).await
|
|
}
|
|
|
|
async fn read_secrets(pool: &mut DbPool<'_>) -> Result<Option<Self>, Error> {
|
|
let conn = &mut get_conn(pool).await?;
|
|
secret.first(conn).await.optional()
|
|
}
|
|
}
|