This commit is contained in:
jpmvaz
2026-09-13 20:10:17 +01:00
parent 9b5cc30fb4
commit b192fb3f17
482 changed files with 0 additions and 48205 deletions
+26
View File
@@ -0,0 +1,26 @@
'use strict';
const { db } = require('../db');
function getSetting(key, fallback = null) {
const row = db.prepare('SELECT value FROM settings WHERE key = ?').get(key);
return row ? row.value : fallback;
}
function setSetting(key, value) {
db.prepare(
`INSERT INTO settings (key, value) VALUES (?, ?)
ON CONFLICT(key) DO UPDATE SET value = excluded.value`
).run(key, value == null ? null : String(value));
}
function getJSON(key, fallback = {}) {
const raw = getSetting(key);
if (!raw) return fallback;
try { return JSON.parse(raw); } catch { return fallback; }
}
function setJSON(key, obj) {
setSetting(key, JSON.stringify(obj));
}
module.exports = { getSetting, setSetting, getJSON, setJSON };