Skip to content

Commit

Permalink
Fix updates of sql.js breaking this app
Browse files Browse the repository at this point in the history
  • Loading branch information
erikhofer committed May 2, 2024
1 parent e24b2de commit 3630fbc
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/DatabaseResult/DatabaseResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();
Expand Down

0 comments on commit 3630fbc

Please sign in to comment.