feat(database): add event log repository

Refs: #93
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 835e1d0edf
commit 1e4bfba3cf
1 file changed
+13
@@ -0,0 +1,13 @@
import { getDatabase } from '../index.js';
export function logEvent({ guildId = null, type, actorId = null, payload = null }) {
getDatabase()
.prepare('INSERT INTO event_logs (guild_id, type, actor_id, payload) VALUES (?, ?, ?, ?)')
.run(guildId, type, actorId, payload ? JSON.stringify(payload) : null);
}
export function purgeEventsOlderThan(days) {
return getDatabase()
.prepare("DELETE FROM event_logs WHERE created_at < datetime('now', ?)")
.run(`-${days} days`).changes;
}