Add web site settings

This commit is contained in:
Greg Burri 2025-01-19 21:05:46 +01:00
parent 65489e7692
commit f1ea7841a2
8 changed files with 74 additions and 19 deletions

View file

@ -16,6 +16,7 @@ use tracing::{event, Level};
use crate::consts;
pub mod recipe;
pub mod settings;
pub mod user;
const CURRENT_DB_VERSION: u32 = 1;

View file

@ -0,0 +1,26 @@
use std::str::FromStr;
use super::{Connection, DBError, Result};
impl Connection {
pub async fn get_new_user_registration_enabled(&self) -> Result<bool> {
self.get("new_user_registration_enabled").await
}
async fn get<T>(&self, name: &str) -> Result<T>
where
T: FromStr,
{
let v: String = sqlx::query_scalar("SELECT [value] FROM [Settings] WHERE [name] = $1")
.bind(name)
.fetch_one(&self.pool)
.await?;
T::from_str(&v).map_err(|_| {
DBError::Other(format!(
"Can't convert string value \"{}\" when reading setting {}",
v, name
))
})
}
}