from typing import Optional from .core import isoformat, utcnow from .db import ctl_execute, ctl_fetch_one def get_setting_value(key: str) -> Optional[str]: row = ctl_fetch_one("SELECT value FROM app_settings WHERE key = ?", (key,)) if row is None: return None return row["value"] def set_setting_value(key: str, value: str, category: str = "GENERAL") -> None: now = isoformat(utcnow()) ctl_execute( """ INSERT INTO app_settings (key, category, value, updated_at) VALUES (?, ?, ?, ?) ON CONFLICT(key) DO UPDATE SET category = excluded.category, value = excluded.value, updated_at = excluded.updated_at """, (key, category, value, now), ) def delete_setting_value(key: str) -> None: ctl_execute("DELETE FROM app_settings WHERE key = ?", (key,))