forge
Explore
Log in

Don't you dare go Hollow

yumush

Clone
★ 0

0 watching0 forksRustAGPL-3.06.8 MiB27ceb05Tahinli8 hours ago399 commits

settings.rs26 lines, 624 bytesHistoryRawDownload
1use common::model::ServerSettings;
2
3use super::{Connection, maybe, run};
4use crate::error::ServerError;
5
6pub 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
17pub 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}