use crate::{db::Pool, error::AppResult}; use std::collections::HashMap; pub async fn get_all(pool: &Pool) -> AppResult> { let rows: Vec<(String, String)> = sqlx::query_as("SELECT key, value FROM settings") .fetch_all(pool) .await?; Ok(rows.into_iter().collect()) } pub async fn upsert(pool: &Pool, key: &str, value: &str) -> AppResult<()> { let now = chrono::Utc::now().to_rfc3339(); sqlx::query( "INSERT INTO settings (key, value, updated_at) VALUES (?, ?, ?) \ ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at", ) .bind(key) .bind(value) .bind(&now) .execute(pool) .await?; Ok(()) }