refactor(all): uniformisation
This commit is contained in:
89 files changed
+10215
-10215
No files matched your search
@@ -1,33 +1,33 @@
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a setting without throwing when the database is not ready (tests, early startup).
|
||||
* Never use it when a missing database should be an error.
|
||||
*/
|
||||
export function resolveSetting(guildId, key, fallback = null) {
|
||||
try {
|
||||
return getSetting(guildId, key, fallback);
|
||||
} catch {
|
||||
return 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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a setting without throwing when the database is not ready (tests, early startup).
|
||||
* Never use it when a missing database should be an error.
|
||||
*/
|
||||
export function resolveSetting(guildId, key, fallback = null) {
|
||||
try {
|
||||
return getSetting(guildId, key, fallback);
|
||||
} catch {
|
||||
return 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);
|
||||
}
|
||||
Reference in new issue
Block a user