diff --git a/lib/db.js b/lib/db.js index 0983372..a613a79 100644 --- a/lib/db.js +++ b/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 [[]];