Skip to content

Commit 3455108

Browse files
committed
Merge branch 'main' into chore/3.53.0
# Conflicts: # package-lock.json # package.json
2 parents 92d616d + 0aa4441 commit 3455108

5 files changed

Lines changed: 358 additions & 723 deletions

File tree

README.md

Lines changed: 66 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
SQLite Wasm conveniently wrapped as an ES Module.
44

5+
## Installation
6+
7+
```bash
8+
npm install @sqlite.org/sqlite-wasm
9+
```
10+
511
## Bug reports
612

713
> [!Warning]
@@ -21,81 +27,16 @@ SQLite Wasm conveniently wrapped as an ES Module.
2127
> Node.js is currently only supported for in-memory databases without
2228
> persistence.
2329
24-
## Installation
25-
26-
```bash
27-
npm install @sqlite.org/sqlite-wasm
28-
```
29-
3030
## Usage
3131

32-
There are three ways to use SQLite Wasm:
32+
There are two ways to use SQLite Wasm:
3333

34-
- [in the main thread with a wrapped worker](#in-a-wrapped-worker-with-opfs-if-available)
35-
(🏆 preferred option)
3634
- [in a worker](#in-a-worker-with-opfs-if-available)
3735
- [in the main thread](#in-the-main-thread-without-opfs)
3836

3937
Only the worker versions allow you to use the origin private file system (OPFS)
4038
storage back-end.
4139

42-
### In a wrapped worker (with OPFS if available):
43-
44-
> [!Warning]
45-
>
46-
> For this to work, you need to set the following headers on your server:
47-
>
48-
> `Cross-Origin-Opener-Policy: same-origin`
49-
>
50-
> `Cross-Origin-Embedder-Policy: require-corp`
51-
52-
```ts
53-
import {
54-
sqlite3Worker1Promiser,
55-
type Worker1Promiser,
56-
} from '@sqlite.org/sqlite-wasm';
57-
58-
const log = console.log;
59-
const error = console.error;
60-
61-
const initializeSQLite = async () => {
62-
try {
63-
log('Loading and initializing SQLite3 module...');
64-
65-
const promiser = await new Promise<Worker1Promiser>((resolve) => {
66-
sqlite3Worker1Promiser({
67-
onready: resolve,
68-
});
69-
});
70-
71-
log('Done initializing. Running demo...');
72-
73-
const configResponse = await promiser('config-get', {});
74-
log('Running SQLite3 version', configResponse.result.version.libVersion);
75-
76-
const openResponse = await promiser('open', {
77-
filename: 'file:mydb.sqlite3?vfs=opfs',
78-
});
79-
const { dbId } = openResponse;
80-
log(
81-
'OPFS is available, created persisted database at',
82-
openResponse.result.filename.replace(/^file:(.*?)\?vfs=opfs$/, '$1'),
83-
);
84-
// Your SQLite code here.
85-
} catch (err) {
86-
if (!(err instanceof Error)) {
87-
err = new Error(err.result.message);
88-
}
89-
error(err.name, err.message);
90-
}
91-
};
92-
93-
await initializeSQLite();
94-
```
95-
96-
The `promiser` object above implements the
97-
[Worker1 API](https://sqlite.org/wasm/doc/trunk/api-worker1.md#worker1-methods).
98-
9940
### In a worker (with OPFS if available):
10041

10142
> [!Warning]
@@ -115,16 +56,13 @@ const worker = new Worker('worker.js', { type: 'module' });
11556
// In `worker.js`.
11657
import sqlite3InitModule from '@sqlite.org/sqlite-wasm';
11758

118-
const log = console.log;
119-
const error = console.error;
120-
12159
const start = (sqlite3) => {
122-
log('Running SQLite3 version', sqlite3.version.libVersion);
60+
console.log('Running SQLite3 version', sqlite3.version.libVersion);
12361
const db =
12462
'opfs' in sqlite3
12563
? new sqlite3.oo1.OpfsDb('/mydb.sqlite3')
12664
: new sqlite3.oo1.DB('/mydb.sqlite3', 'ct');
127-
log(
65+
console.log(
12866
'opfs' in sqlite3
12967
? `OPFS is available, created persisted database at ${db.filename}`
13068
: `OPFS is not available, created transient database ${db.filename}`,
@@ -134,51 +72,47 @@ const start = (sqlite3) => {
13472

13573
const initializeSQLite = async () => {
13674
try {
137-
log('Loading and initializing SQLite3 module...');
75+
console.log('Loading and initializing SQLite3 module...');
13876
const sqlite3 = await sqlite3InitModule();
139-
log('Done initializing. Running demo...');
77+
console.log('Done initializing. Running demo...');
14078
start(sqlite3);
14179
} catch (err) {
142-
error('Initialization error:', err.name, err.message);
80+
console.error('Initialization error:', err.name, err.message);
14381
}
14482
};
14583

14684
initializeSQLite();
14785
```
14886

14987
The `db` object above implements the
150-
[Object Oriented API #1](https://sqlite.org/wasm/doc/trunk/api-oo1.md).
88+
[Object-Oriented API #1](https://sqlite.org/wasm/doc/trunk/api-oo1.md).
15189

15290
### In the main thread (without OPFS):
15391

15492
```js
15593
import sqlite3InitModule from '@sqlite.org/sqlite-wasm';
15694

157-
const log = console.log;
158-
const error = console.error;
159-
16095
const start = (sqlite3) => {
16196
log('Running SQLite3 version', sqlite3.version.libVersion);
16297
const db = new sqlite3.oo1.DB('/mydb.sqlite3', 'ct');
16398
// Your SQLite code here.
16499
};
165-
166100
const initializeSQLite = async () => {
167101
try {
168-
log('Loading and initializing SQLite3 module...');
102+
console.log('Loading and initializing SQLite3 module...');
169103
const sqlite3 = await sqlite3InitModule();
170-
log('Done initializing. Running demo...');
104+
console.log('Done initializing. Running demo...');
171105
start(sqlite3);
172106
} catch (err) {
173-
error('Initialization error:', err.name, err.message);
107+
console.error('Initialization error:', err.name, err.message);
174108
}
175109
};
176110

177111
initializeSQLite();
178112
```
179113

180114
The `db` object above implements the
181-
[Object Oriented API #1](https://sqlite.org/wasm/doc/trunk/api-oo1.md).
115+
[Object-Oriented API #1](https://sqlite.org/wasm/doc/trunk/api-oo1.md).
182116

183117
## Usage with vite
184118

@@ -236,67 +170,75 @@ for this package.
236170

237171
## Building the SQLite Wasm locally
238172

239-
1. Build the Docker image:
173+
1. Build the Docker image:
240174

241-
```bash
242-
docker build -t sqlite-wasm-builder:env .
243-
```
175+
```bash
176+
docker build -t sqlite-wasm-builder:env .
177+
```
244178

245-
2. Run the build:
179+
2. Run the build:
246180

247-
**Unix (Linux/macOS):**
181+
**Unix (Linux/macOS):**
248182

249-
```bash
250-
docker run --rm \
251-
-e SQLITE_REF="master" \
252-
-v "$(pwd)/out":/out \
253-
-v "$(pwd)/src/bin":/src/bin \
254-
sqlite-wasm-builder:env build
255-
```
183+
```bash
184+
docker run --rm \
185+
-e SQLITE_REF="master" \
186+
-v "$(pwd)/out":/out \
187+
-v "$(pwd)/src/bin":/src/bin \
188+
sqlite-wasm-builder:env build
189+
```
256190

257-
**Windows (PowerShell):**
191+
**Windows (PowerShell):**
258192

259-
```powershell
260-
docker run --rm `
261-
-e SQLITE_REF="master" `
262-
-v "${PWD}/out:/out" `
263-
-v "${PWD}/src/bin:/src/bin" `
264-
sqlite-wasm-builder:env build
265-
```
193+
```powershell
194+
docker run --rm `
195+
-e SQLITE_REF="master" `
196+
-v "${PWD}/out:/out" `
197+
-v "${PWD}/src/bin:/src/bin" `
198+
sqlite-wasm-builder:env build
199+
```
266200

267-
**Windows (Command Prompt):**
201+
**Windows (Command Prompt):**
268202

269-
```cmd
270-
docker run --rm ^
271-
-e SQLITE_REF="master" ^
272-
-v "%cd%/out:/out" ^
273-
-v "%cd%/src/bin:/src/bin" ^
274-
sqlite-wasm-builder:env build
275-
```
203+
```cmd
204+
docker run --rm ^
205+
-e SQLITE_REF="master" ^
206+
-v "%cd%/out:/out" ^
207+
-v "%cd%/src/bin:/src/bin" ^
208+
sqlite-wasm-builder:env build
209+
```
276210

277211
## Running tests
278212

279213
The test suite consists of Node.js tests and browser-based tests (using Vitest
280214
Browser Mode). Tests aim to sanity-check the exported scripts. We test for
281215
correct exports and **very** basic functionality.
282216

283-
1. Install dependencies:
217+
1. Install dependencies:
218+
219+
```bash
220+
npm install
221+
```
222+
223+
2. Install Playwright browsers (required for browser tests):
284224

285-
```bash
286-
npm install
287-
```
225+
```bash
226+
npx playwright install chromium --with-deps --no-shell
227+
```
288228

289-
2. Install Playwright browsers (required for browser tests):
229+
3. Run all tests:
290230

291-
```bash
292-
npx playwright install chromium --with-deps --no-shell
293-
```
231+
```bash
232+
npm test
233+
```
294234

295-
3. Run all tests:
235+
## Deprecations
296236

297-
```bash
298-
npm test
299-
```
237+
The Worker1 and Promiser1 APIs are, as of 2026-04-15, deprecated. They _will not
238+
be removed_, but they also will not be extended further. It is their author's
239+
considered opinion that they are too fragile, too imperformant, and too limited
240+
for any non-toy software, and their use is _actively discouraged_. The "correct"
241+
way to use this library is documented in [Usage](#usage) section above.
300242

301243
## License
302244

0 commit comments

Comments
 (0)