From 3630fbc995b8740a11587b3c136ad3c304544c90 Mon Sep 17 00:00:00 2001 From: Erik Hofer Date: Thu, 2 May 2024 20:10:47 +0200 Subject: [PATCH] Fix updates of sql.js breaking this app --- src/DatabaseResult/DatabaseResult.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/DatabaseResult/DatabaseResult.tsx b/src/DatabaseResult/DatabaseResult.tsx index 7cc27a1..f7aa99c 100644 --- a/src/DatabaseResult/DatabaseResult.tsx +++ b/src/DatabaseResult/DatabaseResult.tsx @@ -2,6 +2,9 @@ import { Alert, Table } from "solid-bootstrap"; import { For, Show } from "solid-js"; import initSqlJs from "sql.js"; +// Use the bundled WASM binaries so that updates to the hosted version don' break this app +const sqlJsFiles = import.meta.glob('/node_modules/sql.js/dist/*', { query: 'url', eager: true }); + const INIT_SQL = ` CREATE TABLE users (id int, name char, password char); INSERT INTO users VALUES (1, 'erik', '123'); @@ -12,9 +15,7 @@ INSERT INTO users VALUES (5, 'bob', '333'); `; const SQL = await initSqlJs({ - // Required to load the wasm binary asynchronously. Of course, you can host it wherever you want - // You can omit locateFile completely when running in node - locateFile: (file) => `https://sql.js.org/dist/${file}`, + locateFile: (file) => sqlJsFiles[file] as string, }); const db = new SQL.Database();