@birchill/nice-sqlite-wasm 0.0.2 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -4
- package/dist/sqlite-rev.txt +1 -0
- package/dist/sqlite3.d.ts +4 -1
- package/dist/sqlite3.js +18 -15
- package/dist/sqlite3.wasm +0 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
This is a custom build of SQLite that only supports the "opfs-sahpool" VFS.
|
|
4
4
|
It's "nice" because:
|
|
5
5
|
|
|
6
|
-
- It
|
|
6
|
+
- It removes the "opfs" VFS and worker parts of the JS bindings making for a
|
|
7
7
|
smaller bundle size.
|
|
8
|
-
- It allows
|
|
9
|
-
|
|
8
|
+
- It allows overriding the `locateFile` function so that you can provide a
|
|
9
|
+
custom path for the WASM module (e.g. in order to support cache-busting
|
|
10
|
+
filenames) or even a `Response` object (e.g. so you can abort the download).
|
|
10
11
|
- It fixes some warnings that otherwise might occur at build or run-time
|
|
11
12
|
(e.g. the COOP/COEP header warning which is only relevant to the "opfs" VFS
|
|
12
13
|
and a warning about dependencies based on expressions).
|
|
@@ -14,6 +15,9 @@ It's "nice" because:
|
|
|
14
15
|
In general, it should be nicer for apps using bundlers that only need the
|
|
15
16
|
"opfs-sahpool" VFS.
|
|
16
17
|
|
|
18
|
+
As an extra bonus, the whole build (including building the WASM module) is done
|
|
19
|
+
in CI and published to npm with provenance data so you get full traceability.
|
|
20
|
+
|
|
17
21
|
> [!NOTE]
|
|
18
22
|
> The JS/WASM part of SQLite is under heavy development and is expected to
|
|
19
23
|
> change a lot in future (e.g. using WASI instead of Emscripten). As a result
|
|
@@ -24,7 +28,116 @@ For the official SQLite WASM package see
|
|
|
24
28
|
|
|
25
29
|
## Usage
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
Install:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
npm install @birchill/nice-sqlite-wasm
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
You _could_ probably just do an `import sqlite3InitModule from
|
|
38
|
+
'@birchill/nice-sqlite-wasm'` and be done with it but the whole point of this
|
|
39
|
+
module is to allow you to set it up for better caching and pre-loading.
|
|
40
|
+
How you do that will depend on your bundler.
|
|
41
|
+
|
|
42
|
+
Following is an example for [rspack](https://rspack.rs).
|
|
43
|
+
|
|
44
|
+
### rspack
|
|
45
|
+
|
|
46
|
+
First, we set up a way to generated the name of the WASM module so we can pass
|
|
47
|
+
it to `sqlite3InitModule`.
|
|
48
|
+
|
|
49
|
+
In your `rspack.config.js`:
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
export default defineConfig((env) => {
|
|
53
|
+
// ...
|
|
54
|
+
module: {
|
|
55
|
+
rules: [
|
|
56
|
+
{ resourceQuery: /url$/, type: 'asset/resource' },
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Second, we set up rspack to produce the desired output filename for the asset,
|
|
63
|
+
otherwise you'll get something like `[hash].wasm` which isn't very helpful.
|
|
64
|
+
|
|
65
|
+
Furthermore, we want to drop the query string we enabled above.
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
export default defineConfig((env) => {
|
|
69
|
+
// ...
|
|
70
|
+
output: {
|
|
71
|
+
assetModuleFilename: (fileInfo) => {
|
|
72
|
+
// Generate a cacheable but readable filename for WASM files
|
|
73
|
+
if (
|
|
74
|
+
fileInfo.filename.endsWith('.wasm') ||
|
|
75
|
+
fileInfo.filename.endsWith('.wasm?url')
|
|
76
|
+
) {
|
|
77
|
+
return '[name].[hash].wasm';
|
|
78
|
+
}
|
|
79
|
+
return '[hash][ext][query]';
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Then in your worker code:
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
import wasmUrl from '@birchill/nice-sqlite-wasm/sqlite3.wasm?url';
|
|
89
|
+
import sqlite3InitModule from '@birchill/nice-sqlite-wasm';
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Then when you initialize SQLite:
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
const sqlite = await sqlite3InitModule({
|
|
96
|
+
// Override SQLite's locateFile implementation which wants to resolve
|
|
97
|
+
// the SQLite WASM binary relative to the source directory instead of
|
|
98
|
+
// the asset name assigned by rspack.
|
|
99
|
+
locateFile: (file) => {
|
|
100
|
+
if (file === 'sqlite3.wasm') {
|
|
101
|
+
// Since we strip the query string in our `assetModuleFilename`
|
|
102
|
+
// option in rspack.config.js we don't need to worry about dropping
|
|
103
|
+
// it here.
|
|
104
|
+
//
|
|
105
|
+
// If we were to stop doing that, however, we'd need to do
|
|
106
|
+
// something like:
|
|
107
|
+
//
|
|
108
|
+
// return new URL(wasmUrl, self.location.href).pathname;
|
|
109
|
+
//
|
|
110
|
+
// instead.
|
|
111
|
+
return fetch(wasmUrl, {
|
|
112
|
+
credentials: 'same-origin',
|
|
113
|
+
// If you want to make the fetch abortable...
|
|
114
|
+
signal: abortController.signal,
|
|
115
|
+
});
|
|
116
|
+
} else {
|
|
117
|
+
throw new Error(`Unknown file: ${file}`);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
You can also just return `wasmUrl` from `locateFile` if don't need to control
|
|
124
|
+
the fetch yourself.
|
|
125
|
+
|
|
126
|
+
### vite
|
|
127
|
+
|
|
128
|
+
I'm not sure how to configure vite, but if you're only using it for testing
|
|
129
|
+
(i.e. using [vitest](https://vitest.dev/)) then you can just disable
|
|
130
|
+
optimization there as [explained in the official WASM
|
|
131
|
+
module docs](https://github.com/sqlite/sqlite-wasm/#usage-with-vite):
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
// vitest.config.js
|
|
135
|
+
import { defineConfig } from 'vite';
|
|
136
|
+
|
|
137
|
+
export default defineConfig({
|
|
138
|
+
optimizeDeps: { exclude: ['@birchill/nice-sqlite-wasm'] },
|
|
139
|
+
});
|
|
140
|
+
```
|
|
28
141
|
|
|
29
142
|
## Developing
|
|
30
143
|
|
|
@@ -85,6 +198,7 @@ Then update the table below.
|
|
|
85
198
|
| ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
86
199
|
| `0001-locatefile-nullish-coalesce.patch` | Allow a user-provided `locateFile` function to be used (rather than clobbered). |
|
|
87
200
|
| `0002-hardcode-locatefile-path.patch` | Hardcodes the path used in the default `locateFile` implementation so that bundlers don't complain about dependencies based on expressions. |
|
|
201
|
+
| `0003-locatefile-with-response.patch` | Allows a user-provided `locateFile` function to return a `Response` or a `Promise<Response>`. |
|
|
88
202
|
|
|
89
203
|
### Building the WASM module
|
|
90
204
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ba76c160c735437de974c6ea24c890a663214c6b
|
package/dist/sqlite3.d.ts
CHANGED
|
@@ -2241,7 +2241,10 @@ declare type Sqlite3Static = {
|
|
|
2241
2241
|
};
|
|
2242
2242
|
|
|
2243
2243
|
declare type InitOptions = {
|
|
2244
|
-
locateFile?: (
|
|
2244
|
+
locateFile?: (
|
|
2245
|
+
path: string,
|
|
2246
|
+
prefix: string,
|
|
2247
|
+
) => string | Response | Promise<Response>;
|
|
2245
2248
|
print?: (msg: string) => void;
|
|
2246
2249
|
printErr?: (msg: string) => void;
|
|
2247
2250
|
};
|
package/dist/sqlite3.js
CHANGED
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
/*
|
|
27
27
|
** This code was built from sqlite3 version...
|
|
28
28
|
**
|
|
29
|
-
** SQLITE_VERSION "3.51.
|
|
30
|
-
** SQLITE_VERSION_NUMBER
|
|
31
|
-
** SQLITE_SOURCE_ID "
|
|
29
|
+
** SQLITE_VERSION "3.51.2"
|
|
30
|
+
** SQLITE_VERSION_NUMBER 3051002
|
|
31
|
+
** SQLITE_SOURCE_ID "2026-01-09 17:27:48 b270f8339eb13b504d0b2ba154ebca966b7dde08e40c3ed7d559749818cbalt1"
|
|
32
32
|
**
|
|
33
|
-
** Emscripten SDK:
|
|
33
|
+
** Emscripten SDK: 5.0.0
|
|
34
34
|
**
|
|
35
35
|
*/
|
|
36
36
|
|
|
@@ -73,7 +73,10 @@ async function sqlite3InitModule(moduleArg = {}) {
|
|
|
73
73
|
'undefined' === typeof scriptDirectory ? '' : scriptDirectory
|
|
74
74
|
);
|
|
75
75
|
sims.debugModule('instantiateWasm() uri =', uri, 'sIMS =', this);
|
|
76
|
-
const
|
|
76
|
+
const response =
|
|
77
|
+
uri instanceof Response || uri instanceof Promise
|
|
78
|
+
? uri
|
|
79
|
+
: fetch(uri, { credentials: 'same-origin' });
|
|
77
80
|
const finalThen = (arg) => {
|
|
78
81
|
arg.imports = imports;
|
|
79
82
|
sims.instantiateWasm = arg;
|
|
@@ -81,9 +84,9 @@ async function sqlite3InitModule(moduleArg = {}) {
|
|
|
81
84
|
};
|
|
82
85
|
const loadWasm = WebAssembly.instantiateStreaming
|
|
83
86
|
? async () =>
|
|
84
|
-
WebAssembly.instantiateStreaming(
|
|
87
|
+
WebAssembly.instantiateStreaming(response, imports).then(finalThen)
|
|
85
88
|
: async () =>
|
|
86
|
-
|
|
89
|
+
Promise.resolve(response)
|
|
87
90
|
.then((response) => response.arrayBuffer())
|
|
88
91
|
.then((bytes) => WebAssembly.instantiate(bytes, imports))
|
|
89
92
|
.then(finalThen);
|
|
@@ -9716,17 +9719,17 @@ async function sqlite3InitModule(moduleArg = {}) {
|
|
|
9716
9719
|
});
|
|
9717
9720
|
globalThis.sqlite3ApiBootstrap.initializers.push(function (sqlite3) {
|
|
9718
9721
|
sqlite3.version = {
|
|
9719
|
-
libVersion: '3.51.
|
|
9720
|
-
libVersionNumber:
|
|
9722
|
+
libVersion: '3.51.2',
|
|
9723
|
+
libVersionNumber: 3051002,
|
|
9721
9724
|
sourceId:
|
|
9722
|
-
'
|
|
9723
|
-
downloadVersion:
|
|
9725
|
+
'2026-01-09 17:27:48 b270f8339eb13b504d0b2ba154ebca966b7dde08e40c3ed7d559749818cbalt1',
|
|
9726
|
+
downloadVersion: 3510200,
|
|
9724
9727
|
scm: {
|
|
9725
9728
|
'sha3-256':
|
|
9726
|
-
'
|
|
9729
|
+
'b270f8339eb13b504d0b2ba154ebca966b7dde08e40c3ed7d559749818cbalt1',
|
|
9727
9730
|
branch: 'branch-3.51',
|
|
9728
|
-
tags: 'release version-3.51.
|
|
9729
|
-
datetime: '
|
|
9731
|
+
tags: 'release version-3.51.2',
|
|
9732
|
+
datetime: '2026-01-09T17:27:48.405Z',
|
|
9730
9733
|
},
|
|
9731
9734
|
};
|
|
9732
9735
|
});
|
|
@@ -10261,11 +10264,11 @@ async function sqlite3InitModule(moduleArg = {}) {
|
|
|
10261
10264
|
stmt = null;
|
|
10262
10265
|
}
|
|
10263
10266
|
} finally {
|
|
10264
|
-
wasm.scopedAllocPop(stack);
|
|
10265
10267
|
if (stmt) {
|
|
10266
10268
|
__execLock.delete(stmt);
|
|
10267
10269
|
stmt.finalize();
|
|
10268
10270
|
}
|
|
10271
|
+
wasm.scopedAllocPop(stack);
|
|
10269
10272
|
}
|
|
10270
10273
|
return arg.returnVal();
|
|
10271
10274
|
},
|
package/dist/sqlite3.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@birchill/nice-sqlite-wasm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
"publishConfig": {
|
|
24
24
|
"provenance": true
|
|
25
25
|
},
|
|
26
|
-
"publishedAt": "2026-01-
|
|
26
|
+
"publishedAt": "2026-01-26T07:39:51.875Z"
|
|
27
27
|
}
|