Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(client/lightweight): statements with parameters not working
Elian Doran724af8e103cb
diff --git a/apps/client/src/lightweight/sql_provider.ts b/apps/client/src/lightweight/sql_provider.tsindex b86b36eb67..7256327887 100644--- a/apps/client/src/lightweight/sql_provider.ts+++ b/apps/client/src/lightweight/sql_provider.ts@@ -120,7 +120,22 @@ class WasmStatement implements Statement {// Handle single object with named parametersif (params.length === 1 && typeof params[0] === "object" && params[0] !== null && !Array.isArray(params[0])) {- const bindings = params[0] as { [paramName: string]: BindableValue };+ const inputBindings = params[0] as { [paramName: string]: BindableValue };++ // SQLite WASM expects parameter names to include the prefix (@ : or $)+ // better-sqlite3 automatically maps unprefixed names to @name+ // We need to add the @ prefix for compatibility+ const bindings: { [paramName: string]: BindableValue } = {};+ for (const [key, value] of Object.entries(inputBindings)) {+ // If the key already has a prefix, use it as-is+ if (key.startsWith('@') || key.startsWith(':') || key.startsWith('$')) {+ bindings[key] = value;+ } else {+ // Add @ prefix to match better-sqlite3 behavior+ bindings[`@${key}`] = value;+ }+ }+this.stmt.bind(bindings);} else {// Handle positional parameters - flatten and cast to BindableValue[]diff --git a/packages/trilium-core/src/services/sql/sql.ts b/packages/trilium-core/src/services/sql/sql.tsindex 27ab4c2ca0..d878936f2c 100644--- a/packages/trilium-core/src/services/sql/sql.ts+++ b/packages/trilium-core/src/services/sql/sql.ts@@ -277,6 +277,8 @@ export class SqlService {return null;}+ console.error(`Error executing query: ${query} with parameters ${JSON.stringify((e as any).params || [])}`);+throw e;}