| 1 | use common::model::ServerSettings; |
| 2 | |
| 3 | use super::{Connection, maybe, run}; |
| 4 | use crate::error::ServerError; |
| 5 | |
| 6 | pub async fn read(db: &Connection) -> Result<ServerSettings, ServerError> { |
| 7 | Ok(maybe( |
| 8 | db, |
| 9 | "SELECT data FROM server_settings WHERE id = 1", |
| 10 | (), |
| 11 | |r| r.blob::<ServerSettings>(), |
| 12 | ) |
| 13 | .await? |
| 14 | .unwrap_or_default()) |
| 15 | } |
| 16 | |
| 17 | pub async fn update(settings: &ServerSettings, db: &Connection) -> Result<(), ServerError> { |
| 18 | run( |
| 19 | db, |
| 20 | "INSERT OR REPLACE INTO server_settings (id, data) VALUES (1, ?1)", |
| 21 | (bitcode::encode(settings),), |
| 22 | ) |
| 23 | .await?; |
| 24 | |
| 25 | Ok(()) |
| 26 | } |