From a6f52fff3ea718fa7d25525a2b4bfb029c191895 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 6 Jan 2026 22:20:53 +0200 Subject: [PATCH] fix(client/lightweight): raw SQL queries not working --- apps/client/src/lightweight/sql_provider.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/client/src/lightweight/sql_provider.ts b/apps/client/src/lightweight/sql_provider.ts index 899ab4e36..05916adda 100644 --- a/apps/client/src/lightweight/sql_provider.ts +++ b/apps/client/src/lightweight/sql_provider.ts @@ -13,6 +13,8 @@ type Sqlite3PreparedStatement = ReturnType; * expected by trilium-core. */ class WasmStatement implements Statement { + private isRawMode = false; + constructor( private stmt: Sqlite3PreparedStatement, private db: Sqlite3Database @@ -36,7 +38,7 @@ class WasmStatement implements Statement { this.bindParams(Array.isArray(params) ? params : params !== undefined ? [params] : []); try { if (this.stmt.step()) { - return this.stmt.get({}); + return this.isRawMode ? this.stmt.get([]) : this.stmt.get({}); } return undefined; } finally { @@ -49,7 +51,7 @@ class WasmStatement implements Statement { const results: unknown[] = []; try { while (this.stmt.step()) { - results.push(this.stmt.get({})); + results.push(this.isRawMode ? this.stmt.get([]) : this.stmt.get({})); } return results; } finally { @@ -60,6 +62,7 @@ class WasmStatement implements Statement { iterate(...params: unknown[]): IterableIterator { this.bindParams(params); const stmt = this.stmt; + const isRaw = this.isRawMode; return { [Symbol.iterator]() { @@ -67,7 +70,7 @@ class WasmStatement implements Statement { }, next(): IteratorResult { if (stmt.step()) { - return { value: stmt.get({}), done: false }; + return { value: isRaw ? stmt.get([]) : stmt.get({}), done: false }; } stmt.reset(); return { value: undefined, done: true }; @@ -75,10 +78,10 @@ class WasmStatement implements Statement { }; } - raw(_toggleState?: boolean): this { - // SQLite WASM doesn't have a direct equivalent to raw mode - // raw mode returns arrays instead of objects - console.warn("raw() mode is not fully supported in WASM SQLite provider"); + raw(toggleState?: boolean): this { + // In raw mode, rows are returned as arrays instead of objects + // If toggleState is undefined, enable raw mode (better-sqlite3 behavior) + this.isRawMode = toggleState !== undefined ? toggleState : true; return this; }