Fix: normalize Surreal query response

This commit is contained in:
2026-03-15 15:06:35 -07:00
parent d7dabea20f
commit eda38cb58e

View File

@@ -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 = {}) { async query(sql, vars = {}) {
if (!this.connected) return [[]]; if (!this.connected) return [[]];
try { try {
return await this.client.query(sql, vars); const raw = await this.client.query(sql, vars);
return this._normalizeQueryResult(raw);
} catch (e) { } catch (e) {
console.error('[DB] Query error:', e.message); console.error('[DB] Query error:', e.message);
return [[]]; return [[]];