-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
29 lines (26 loc) · 974 Bytes
/
config.js
File metadata and controls
29 lines (26 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const db = require('./db');
async function getConfig(key) {
try {
const [rows] = await db.query('SELECT value FROM config WHERE key_name = ?', [key]);
if (rows.length === 0) {
console.warn(`⚠️ [WARN] Konfigurationswert nicht gefunden: ${key}`);
return null;
}
return rows[0].value;
} catch (error) {
console.error(`❌ [ERROR] Fehler beim Abrufen der Konfiguration (${key}):`, error);
return null;
}
}
async function setConfig(key, value) {
try {
await db.query(
'INSERT INTO config (key_name, value) VALUES (?, ?) ON DUPLICATE KEY UPDATE value = VALUES(value)',
[key, value]
);
console.log(`✅ [INFO] Konfiguration erfolgreich gespeichert: ${key} = ${value}`);
} catch (error) {
console.error(`❌ [ERROR] Fehler beim Speichern der Konfiguration (${key}):`, error);
}
}
module.exports = { getConfig, setConfig };