Add web site settings
This commit is contained in:
parent
65489e7692
commit
f1ea7841a2
8 changed files with 74 additions and 19 deletions
|
|
@ -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;
|
||||
|
|
|
|||
26
backend/src/data/db/settings.rs
Normal file
26
backend/src/data/db/settings.rs
Normal 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
|
||||
))
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue