From eda38cb58e136c91a59ff43793ea4325057507c9 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Sun, 15 Mar 2026 15:06:35 -0700 Subject: [PATCH] Fix: normalize Surreal query response --- lib/db.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 [[]];