Skip to content

Commit e75c063

Browse files
committed
Make comlink work
1 parent d713ca1 commit e75c063

File tree

6 files changed

+26
-45
lines changed

6 files changed

+26
-45
lines changed
Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import SqliteClient from '/src/sqlite.client.mjs';
1+
import SqliteClient from '/src/sqlite-client.mjs';
22

3-
const sqliteClient = new SqliteClient('/db.sqlite3', '/src/sqlite.worker.mjs');
3+
const sqliteClient = new SqliteClient('/db.sqlite3', '/src/sqlite-worker.mjs');
44

55
await sqliteClient.init();
66

@@ -14,15 +14,4 @@ const rows = await sqliteClient.executeSql(
1414
'SELECT a FROM t ORDER BY a LIMIT 3',
1515
);
1616

17-
console.log(rows);
18-
19-
document.getElementById('sqlite-client').innerHTML =
20-
'<table>' +
21-
'<thead>' +
22-
'<tr>' +
23-
'<th>a</th>' +
24-
'</tr>' +
25-
'</thead>' +
26-
'<tbody>' +
27-
rows.map((row) => '<tr><td> ' + row[0] + '</td></tr>').concat();
28-
'</tbody>' + '</table>';
17+
document.querySelector('.comlink').innerHTML = rows.join('<br />');

demo/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
<title>SQLite Wasm Demo</title>
66
<script type="module" src="script.js"></script>
77
<script type="module" src="main-thread.js"></script>
8-
<script type="module" src="sqlite-client.js"></script>
8+
<script type="module" src="comlink.js"></script>
99
</head>
1010
<body>
1111
<h1>SQLite Wasm Demo</h1>
1212
<h2>Main thread</h2>
1313
<div class="main-thread"></div>
1414
<h2>Worker</h2>
1515
<div class="worker"></div>
16-
<h2>Built-in SQLite Client</h2>
17-
<div id="sqlite-client"></div>
16+
<h2>Main thread using Worker via Comlink</h2>
17+
<div class="comlink"></div>
1818
</body>
1919
</html>

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sqlite.org/sqlite-wasm",
3-
"version": "3.42.0-build1",
3+
"version": "3.42.0-build2",
44
"description": "SQLite Wasm conveniently wrapped as an ES Module.",
55
"keywords": [
66
"sqlite",
@@ -17,7 +17,8 @@
1717
"type": "module",
1818
"files": [
1919
"index.mjs",
20-
"sqlite-wasm/"
20+
"sqlite-wasm/",
21+
"src/"
2122
],
2223
"exports": {
2324
".": {
@@ -56,7 +57,7 @@
5657
"module-workers-polyfill": "^0.3.2",
5758
"node-fetch": "^3.3.1",
5859
"prettier": "^2.8.8",
59-
"publint": "^0.1.12",
60+
"publint": "^0.1.13",
6061
"shx": "^0.3.4"
6162
},
6263
"dependencies": {

src/sqlite-client.mjs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
const log = (...args) => console.log(...args);
2-
const error = (...args) => console.error(...args);
1+
import * as Comlink from '../node_modules/comlink/dist/esm/comlink.mjs';
32

43
export default class SqliteClient {
54
sqliteWorker;
@@ -9,18 +8,14 @@ export default class SqliteClient {
98

109
constructor(dbFile, sqliteWorkerPath) {
1110
if (typeof dbFile !== 'string') {
12-
return error(
13-
"The 'dbFile' parameter passed to the SqliteClient constructor must be of type 'string'. Instead, you passed: '" +
14-
typeof dbFile +
15-
"'",
11+
throw new Error(
12+
`The 'dbFile' parameter passed to the 'SqliteClient' constructor must be of type 'string'. Instead, you passed: '${typeof dbFile}'.`,
1613
);
1714
}
1815

1916
if (typeof sqliteWorkerPath !== 'string') {
20-
return error(
21-
"The 'sqliteWorkerPath' parameter passed to the SqliteClient constructor must be of type 'string'. Instead, you passed: '" +
22-
typeof sqliteWorkerPath +
23-
"'",
17+
throw new Error(
18+
`The 'sqliteWorkerPath' parameter passed to the 'SqliteClient' constructor must be of type 'string'. Instead, you passed: '${typeof sqliteWorkerPath}'.`,
2419
);
2520
}
2621

@@ -42,18 +37,14 @@ export default class SqliteClient {
4237

4338
async executeSql(sqlStatement, bindParameters = []) {
4439
if (typeof sqlStatement !== 'string') {
45-
return error(
46-
"The 'sqlStatement' parameter passed to the 'executeSql' method of the SqliteClient must be of type 'string'. Instead, you passed: '" +
47-
typeof sqlStatement +
48-
"'",
40+
throw new Error(
41+
`The 'sqlStatement' parameter passed to the 'executeSql' method of the 'SqliteClient' must be of type 'string'. Instead, you passed: '${typeof sqlStatement}'.`,
4942
);
5043
}
5144

5245
if (!Array.isArray(bindParameters)) {
53-
return error(
54-
"The 'bindParameters' parameter passed to the 'executeSql' method of the SqliteClient must be of type 'array'. Instead, you passed: '" +
55-
typeof bindParameters +
56-
"'",
46+
throw new Error(
47+
`The 'bindParameters' parameter passed to the 'executeSql' method of the 'SqliteClient' must be of type 'array'. Instead, you passed: '${typeof bindParameters}'.`,
5748
);
5849
}
5950

src/sqlite-worker.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Comlink from 'https://unpkg.com/comlink/dist/esm/comlink.mjs';
1+
import * as Comlink from '../node_modules/comlink/dist/esm/comlink.mjs';
22
import { default as sqlite3InitModule } from '../index.mjs';
33

44
const log = (...args) => console.log(...args);

0 commit comments

Comments
 (0)