2022-11-09 10:05:00 +00:00
|
|
|
use crate::{
|
2024-04-16 12:48:15 +00:00
|
|
|
diesel::OptionalExtension,
|
2022-11-19 04:33:54 +00:00
|
|
|
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.
|
2024-04-16 12:48:15 +00:00
|
|
|
pub async fn init(pool: &mut DbPool<'_>) -> Result<Option<Secret>, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
Self::read_secrets(pool).await
|
2021-10-16 13:33:38 +00:00
|
|
|
}
|
|
|
|
|
2024-04-16 12:48:15 +00:00
|
|
|
async fn read_secrets(pool: &mut DbPool<'_>) -> Result<Option<Self>, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2024-04-16 12:48:15 +00:00
|
|
|
secret.first(conn).await.optional()
|
2022-11-09 10:05:00 +00:00
|
|
|
}
|
2021-10-16 13:33:38 +00:00
|
|
|
}
|