mirror of
https://github.com/multipleof4/KalBot.git
synced 2026-03-17 05:51:02 +00:00
Fix: normalize Surreal query response
This commit is contained in:
16
lib/db.js
16
lib/db.js
@@ -32,10 +32,24 @@ class Database {
|
||||
}
|
||||
}
|
||||
|
||||
_normalizeQueryResult(raw) {
|
||||
if (!Array.isArray(raw)) return [[]];
|
||||
|
||||
return raw.map((entry) => {
|
||||
if (Array.isArray(entry)) return entry;
|
||||
if (entry && typeof entry === 'object' && 'result' in entry) {
|
||||
return Array.isArray(entry.result) ? entry.result : [entry.result];
|
||||
}
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
||||
async query(sql, vars = {}) {
|
||||
if (!this.connected) return [[]];
|
||||
|
||||
try {
|
||||
return await this.client.query(sql, vars);
|
||||
const raw = await this.client.query(sql, vars);
|
||||
return this._normalizeQueryResult(raw);
|
||||
} catch (e) {
|
||||
console.error('[DB] Query error:', e.message);
|
||||
return [[]];
|
||||
|
||||
Reference in New Issue
Block a user