feat(database): add guild settings repository

Refs: #33
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
nocodeandClaude Opus 5 committed 2026-09-13 12:19:10 +02:00
1 parent 1914cee0eb
commit 835e1d0edf
1 file changed
+21
@@ -0,0 +1,21 @@
import { getDatabase } from '../index.js';
export function getSetting(guildId, key, fallback = null) {
const row = getDatabase()
.prepare('SELECT value FROM guild_settings WHERE guild_id = ? AND key = ?')
.get(guildId, key);
return row ? JSON.parse(row.value) : fallback;
}
export function setSetting(guildId, key, value, updatedBy = null) {
getDatabase()
.prepare(
`INSERT INTO guild_settings (guild_id, key, value, updated_by)
VALUES (?, ?, ?, ?)
ON CONFLICT (guild_id, key) DO UPDATE SET
value = excluded.value,
updated_by = excluded.updated_by,
updated_at = datetime('now')`,
)
.run(guildId, key, JSON.stringify(value), updatedBy);
}