@cldmv/sqlite-wasm 0.0.1-placeholder → 0.1.0

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.
Files changed (50) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +565 -3
  3. package/dist/chunk-IEYL6MVW.mjs +2 -0
  4. package/dist/chunk-IRDSVJEM.mjs +2 -0
  5. package/dist/chunk-IXZKMCUU.mjs +2 -0
  6. package/dist/chunk-VOHQWANF.mjs +2 -0
  7. package/dist/chunk-VRZKKYFL.mjs +2 -0
  8. package/dist/chunk-YTH6FRG3.mjs +2 -0
  9. package/dist/drizzle.cjs +26 -0
  10. package/dist/drizzle.mjs +2 -0
  11. package/dist/fs-B55OKCP5.mjs +2 -0
  12. package/dist/host.mjs +2 -0
  13. package/dist/index.cjs +26 -0
  14. package/dist/index.mjs +2 -0
  15. package/dist/opfs-CREACZOE.mjs +2 -0
  16. package/dist/sqlite3.wasm +0 -0
  17. package/dist/worker.mjs +2 -0
  18. package/package.json +150 -3
  19. package/types/src/api/connection.d.mts +86 -0
  20. package/types/src/api/database.d.mts +109 -0
  21. package/types/src/api/error.d.mts +25 -0
  22. package/types/src/api/functions.d.mts +50 -0
  23. package/types/src/api/open.d.mts +90 -0
  24. package/types/src/api/runtime.d.mts +46 -0
  25. package/types/src/api/statement.d.mts +106 -0
  26. package/types/src/api/transaction.d.mts +37 -0
  27. package/types/src/api/values.d.mts +35 -0
  28. package/types/src/core/browser-loader.d.mts +45 -0
  29. package/types/src/core/callbacks.d.mts +49 -0
  30. package/types/src/core/codes.d.mts +17 -0
  31. package/types/src/core/constants.d.mts +75 -0
  32. package/types/src/core/loader.d.mts +126 -0
  33. package/types/src/core/memory.d.mts +48 -0
  34. package/types/src/core/platform.d.mts +40 -0
  35. package/types/src/core/raw.d.mts +48 -0
  36. package/types/src/core/router.d.mts +50 -0
  37. package/types/src/core/vfs-imports.d.mts +58 -0
  38. package/types/src/core/wasi.d.mts +28 -0
  39. package/types/src/drizzle.d.mts +64 -0
  40. package/types/src/index.d.mts +47 -0
  41. package/types/src/node.d.mts +25 -0
  42. package/types/src/vfs/fs.d.mts +72 -0
  43. package/types/src/vfs/memory.d.mts +39 -0
  44. package/types/src/vfs/opfs.d.mts +98 -0
  45. package/types/src/vfs/registry.d.mts +76 -0
  46. package/types/src/worker/client.d.mts +142 -0
  47. package/types/src/worker/engine.d.mts +46 -0
  48. package/types/src/worker/host.d.mts +50 -0
  49. package/types/src/worker/protocol.d.mts +202 -0
  50. package/types/src/worker/share.d.mts +69 -0
package/README.md CHANGED
@@ -1,7 +1,569 @@
1
1
  # @cldmv/sqlite-wasm
2
2
 
3
- This version is a placeholder that reserves the package name so the repository's release workflow can publish it with npm trusted publishing.
3
+ SQLite 3.54.1 compiled to WebAssembly, with one build and one API for Node.js and browsers. Databases are real files on disk in Node, OPFS in a browser worker, or memory anywhere. The API is synchronous wherever the storage is (Node, browser workers), and there is an async client for the browser main thread. Database files are standard SQLite files: ones written by native SQLite open here and the other way round.
4
4
 
5
- SQLite compiled to WebAssembly for Node.js and browsers, with file storage on disk and in OPFS
5
+ The module is built from SQLite's own source archive with wasi-sdk, with no Emscripten runtime and no fork of another wasm SQLite project. SQLite's generators produce the amalgamation from the archive, and nothing in it is patched. The wasm is built in CI from a pinned SQLite version and hash; nothing binary is committed.
6
6
 
7
- Source and real releases: https://github.com/CLDMV/lib-sqlite-wasm
7
+ - Node.js (real files, owner lock between processes) and browser workers (OPFS, Web Locks)
8
+ - WAL by default, with the standard on-disk format
9
+ - User-defined functions, aggregates, window functions and collations
10
+ - Backup, serialize, attach, checkpoint
11
+ - Optional [Drizzle ORM](https://orm.drizzle.team) driver, sync and async
12
+ - Several browser tabs can share one database
13
+
14
+ [![npm version]][npm_version_url] [![npm downloads]][npm_downloads_url] [![GitHub downloads]][github_downloads_url] [![Last commit]][last_commit_url] [![npm last update]][npm_last_update_url] [![coverage]][coverage_url]
15
+
16
+ [![Contributors]][contributors_url] [![Sponsor shinrai]][sponsor_url]
17
+
18
+ ## ✨ What's New
19
+
20
+ ### Latest: v0.1.0 (November 2026)
21
+
22
+ - **First release** — SQLite 3.54.1 compiled to WebAssembly from SQLite's own source archive, with one synchronous API for Node.js (real files, owner lock between processes) and browser workers (OPFS, Web Locks), plus an async client for the browser main thread. WAL by default, standard on-disk files, an optional Drizzle ORM driver, and several browser tabs sharing one database with automatic handover.
23
+ - [View full v0.1.0 Changelog](https://github.com/CLDMV/lib-sqlite-wasm/blob/master/docs/changelog/v0/v0.1.0.md)
24
+
25
+ ## Contents
26
+
27
+ - [What's New](#-whats-new)
28
+ - [Install](#install)
29
+ - [Quick start](#quick-start)
30
+ - [API](#api)
31
+ - [Storage and journal modes](#storage-and-journal-modes)
32
+ - [Locking](#locking)
33
+ - [Browser: worker and host](#browser-worker-and-host)
34
+ - [Multi-tab sharing](#multi-tab-sharing)
35
+ - [Drizzle](#drizzle)
36
+ - [What is compiled in](#what-is-compiled-in)
37
+ - [Requirements](#requirements)
38
+ - [Development](#development)
39
+ - [License](#license)
40
+
41
+ ## Install
42
+
43
+ ```sh
44
+ npm install @cldmv/sqlite-wasm
45
+ ```
46
+
47
+ Drizzle support is optional. Install `drizzle-orm` (`^0.45.0`) next to it if you want it.
48
+
49
+ ### Entry points
50
+
51
+ | Import | What it is |
52
+ | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
53
+ | `@cldmv/sqlite-wasm` | `sqlite.open()` and `sqlite.error`. ESM and CommonJS (`require()` needs Node.js `^20.19.0` or `>=22.13.0`). Works in Node and inside a browser worker. |
54
+ | `@cldmv/sqlite-wasm/host` | Worker side of the main-thread client: `host.listen(self)`. ESM only. |
55
+ | `@cldmv/sqlite-wasm/worker` | Main-thread client: `client.connect(workerUrl, path, options)`. ESM only. |
56
+ | `@cldmv/sqlite-wasm/drizzle` | `drizzle()` and `migrate()`. ESM and CommonJS. |
57
+
58
+ Nothing runs at import time. The wasm module is compiled and instantiated by the first `sqlite.open()`.
59
+
60
+ ## Quick start
61
+
62
+ ### Node.js
63
+
64
+ ```js
65
+ import sqlite from "@cldmv/sqlite-wasm";
66
+
67
+ const db = await sqlite.open("app.sqlite3");
68
+
69
+ db.execute("CREATE TABLE IF NOT EXISTS note (id INTEGER PRIMARY KEY, body TEXT NOT NULL)");
70
+
71
+ const insert = db.prepare("INSERT INTO note (body) VALUES (?)");
72
+ insert.run("hello"); // { changes: 1, rowid: 1 }
73
+
74
+ const add = db.transaction((bodies) => {
75
+ for (const body of bodies) insert.run(body);
76
+ });
77
+ add(["one", "two", "three"]);
78
+
79
+ db.prepare("SELECT * FROM note WHERE id = ?").get(1); // { id: 1, body: "hello" }
80
+ db.prepare("SELECT body FROM note").pluck.all(); // ["hello", "one", "two", "three"]
81
+
82
+ db.close();
83
+ ```
84
+
85
+ `sqlite.open()` is the only async call. Everything after it is synchronous. With CommonJS:
86
+
87
+ ```js
88
+ const sqlite = require("@cldmv/sqlite-wasm");
89
+ const db = await sqlite.open(":memory:");
90
+ ```
91
+
92
+ ### Browser
93
+
94
+ A persistent database lives in OPFS and OPFS's synchronous handles only exist in dedicated workers, so the database runs in a worker and the page talks to it through an async client. The worker file is three lines:
95
+
96
+ ```js
97
+ // db-worker.mjs
98
+ import host from "@cldmv/sqlite-wasm/host";
99
+
100
+ host.listen(self);
101
+ ```
102
+
103
+ The page connects to it:
104
+
105
+ ```js
106
+ import client from "@cldmv/sqlite-wasm/worker";
107
+
108
+ const db = await client.connect(new URL("./db-worker.mjs", import.meta.url), "app.sqlite3");
109
+
110
+ await db.execute("CREATE TABLE IF NOT EXISTS note (id INTEGER PRIMARY KEY, body TEXT NOT NULL)");
111
+ await db.prepare("INSERT INTO note (body) VALUES (?)").run("hello");
112
+ await db.prepare("SELECT * FROM note").all(); // [{ id: 1, body: "hello" }]
113
+ ```
114
+
115
+ Inside a dedicated worker you can also use `sqlite.open()` directly and get the synchronous API on OPFS. `storage: "auto"` on the main thread throws; use the worker client, or `storage: "memory"`.
116
+
117
+ ## API
118
+
119
+ Names are single lowercase words (`statement`, `database`, `row`). A few have a short alias, which is the same function under a second name. Aliases are listed next to their full names below and again in the [alias table](#aliases).
120
+
121
+ ### `sqlite`
122
+
123
+ ```js
124
+ import sqlite from "@cldmv/sqlite-wasm";
125
+ // or: import { open, error, err } from "@cldmv/sqlite-wasm";
126
+ ```
127
+
128
+ | Member | Description |
129
+ | ----------------------------------- | ---------------------------------------------- |
130
+ | `sqlite.open(path, options?)` | Opens a database and resolves to a `database`. |
131
+ | `sqlite.error` (alias `sqlite.err`) | The class of every error SQLite reports. |
132
+
133
+ #### Open options
134
+
135
+ | Option | Default | Description |
136
+ | ---------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
137
+ | `storage` | `"auto"` | `"auto"`, `"fs"`, `"opfs"` or `"memory"`. `"auto"` picks `fs` in Node and `opfs` in a dedicated browser worker. The paths `":memory:"` and `""` always use memory. |
138
+ | `readonly` | `false` | Open read-only. |
139
+ | `create` | `true` | Create the file if it does not exist (ignored when read-only). |
140
+ | `journal` | `"wal"` | `"wal"`, `"truncate"` or `"delete"`. See [journal modes](#journal-modes). |
141
+ | `sync` | `"normal"` | `PRAGMA synchronous`: `"off"`, `"normal"`, `"full"` or `"extra"`. |
142
+ | `foreign` | `true` | Enforce foreign keys. |
143
+ | `timeout` | `5000` | Milliseconds to wait for a lock held by another process or tab. Also the SQLite busy timeout. |
144
+ | `bigint` | `false` | Return every INTEGER as a `bigint`. Integers outside the safe range are always `bigint`. |
145
+ | `lock` | `"beside"` | Node only: how other processes are kept out. See [locking](#locking). |
146
+
147
+ ### `database`
148
+
149
+ ```js
150
+ const db = await sqlite.open("app.sqlite3");
151
+ ```
152
+
153
+ | Member | Description |
154
+ | ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
155
+ | `db.prepare(sql, { bigint }?)` (alias `db.prep`) | Compiles one statement and returns a `statement`. Throws if the SQL holds more than one statement. |
156
+ | `db.execute(sql)` (alias `db.exec`) | Runs one or more statements and discards rows. Returns `db`. |
157
+ | `db.transaction(callback)` (alias `db.tx`) | Wraps `callback` so each call runs in a transaction. See [transactions](#transactions). |
158
+ | `db.pragma.get(name)` | The first value `PRAGMA name` returns. |
159
+ | `db.pragma.set(name, value)` | Runs `PRAGMA name = value` and returns the first value it returns, if any. |
160
+ | `db.pragma.all(name, argument?)` | Every row `PRAGMA name` (or `PRAGMA name(argument)`) returns. |
161
+ | `db.fn.scalar(name, callback, options?)` | Registers a scalar function. |
162
+ | `db.fn.aggregate(name, definition)` (alias `db.fn.agg`) | Registers an aggregate, or a window function when `inverse` is given. |
163
+ | `db.fn.collation(name, compare)` | Registers a collation. |
164
+ | `await db.attach(path, schema, { storage }?)` | Attaches another database file as `schema`. |
165
+ | `await db.detach(schema)` | Detaches it. |
166
+ | `await db.backup(target, { storage, schema }?)` | Copies the database (or an attached `schema`) into the file `target` with SQLite's backup API, replacing what was there. |
167
+ | `db.serialize(schema?)` | The database (or an attached schema) as a `Uint8Array` holding an SQLite file. |
168
+ | `db.checkpoint(mode?)` (alias `db.ckpt`) | Runs a WAL checkpoint; `mode` is `"passive"` (default), `"full"`, `"restart"` or `"truncate"`. Returns `{ busy, log, checkpointed }`. |
169
+ | `db.close()` | Finalizes every statement and closes the connection. A WAL database is checkpointed and its `-wal` file removed, so native SQLite can open it afterwards. Calling it again does nothing. |
170
+ | `db.info.path` | The path the database was opened with. |
171
+ | `db.info.storage` | The storage driver in use. |
172
+ | `db.info.lock` | The lock in effect: `"beside"`, `"temp"`, the folder you passed, `"db"`, `"web"` (OPFS) or `"none"` (memory). `"beside"` reads `"temp"` when it fell back. |
173
+ | `db.info.open` | Whether the connection is still open. |
174
+ | `db.info.transaction` | Whether a transaction is open. |
175
+
176
+ `attach` and `detach` are async because opening a file in OPFS or taking an owner lock is. The `bigint` option of `db.prepare()` overrides the database's setting for that statement.
177
+
178
+ User-defined functions:
179
+
180
+ ```js
181
+ db.fn.scalar("slug", (text) => text.toLowerCase().replaceAll(" ", "-"), { deterministic: true });
182
+
183
+ db.fn.aggregate("total", {
184
+ start: 0,
185
+ step: (sum, value) => sum + value,
186
+ result: (sum) => sum
187
+ });
188
+
189
+ db.fn.collation("by_length", (a, b) => a.length - b.length);
190
+ ```
191
+
192
+ Function options are `deterministic`, `variadic` (accept any number of arguments instead of the callback's declared count) and `bigint` (pass INTEGER arguments as `bigint`). An aggregate's `start` is the initial accumulator, or a function returning a fresh one for each group. Adding `inverse` makes it a window function. If a callback throws, the statement fails with that same exception.
193
+
194
+ ### `statement`
195
+
196
+ | Member | Description |
197
+ | ------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
198
+ | `stmt.run(...parameters)` | Executes the statement and returns `{ changes, rowid }`. |
199
+ | `stmt.get(...parameters)` | The first row as an object, or `undefined`. |
200
+ | `stmt.all(...parameters)` | Every row as an object. |
201
+ | `stmt.iterate(...parameters)` (alias `stmt.iter`) | An iterator over the rows. The statement cannot run again until the iterator finishes or is returned. |
202
+ | `stmt.raw.get / .all / .iterate` (alias `.iter`) | Rows as positional arrays. |
203
+ | `stmt.pluck.get / .all` | The first column only. |
204
+ | `stmt.expand.get / .all` | Rows grouped by source table: `{ table: { column: value } }`, with `"$"` for expressions. |
205
+ | `stmt.bind(...parameters)` | Fixes the parameters for every later run, which must then pass none. Callable once. Returns `stmt`. |
206
+ | `stmt.columns()` (alias `stmt.cols`) | Describes the result columns: `{ name, column, table, database, type }`. |
207
+ | `stmt.close()` | Finalizes the statement. |
208
+ | `stmt.info.sql` | The SQL text. |
209
+ | `stmt.info.reader` | Whether the statement returns rows. |
210
+ | `stmt.info.readonly` | Whether it leaves the database unchanged. |
211
+
212
+ `get`, `all` and `iterate` throw on a statement that returns no rows; use `run()` for those.
213
+
214
+ Parameters are positional (`stmt.run("a", 1)`) or one object of named values whose keys have no `:`, `@` or `$` prefix (`stmt.run({ name: "a" })` for `:name`). Statements are finalized by `close()`, by `db.close()` and, as a safety net, by a `FinalizationRegistry`, so a forgotten statement does not keep the database locked.
215
+
216
+ ### Values
217
+
218
+ | JavaScript | SQLite |
219
+ | --------------------- | ------------------------------------------------ |
220
+ | `null`, `undefined` | `NULL` |
221
+ | safe integer `number` | `INTEGER` |
222
+ | other `number` | `REAL` |
223
+ | `bigint` | `INTEGER` (throws if it does not fit in 64 bits) |
224
+ | `boolean` | `INTEGER` 1 or 0 |
225
+ | `string` | `TEXT` (UTF-8, embedded NUL kept) |
226
+ | `Uint8Array` | `BLOB` |
227
+
228
+ Reading goes the other way: INTEGER is a `number` when it fits in the safe range and a `bigint` otherwise (always `bigint` with `bigint: true`), REAL is a `number`, TEXT a `string`, BLOB a fresh `Uint8Array`, NULL `null`. Anything else (a `Date`, a plain object in a value position) is a `TypeError`.
229
+
230
+ ### Transactions
231
+
232
+ ```js
233
+ const transfer = db.transaction((from, to, amount) => {
234
+ db.prepare("UPDATE account SET balance = balance - ? WHERE id = ?").run(amount, from);
235
+ db.prepare("UPDATE account SET balance = balance + ? WHERE id = ?").run(amount, to);
236
+ });
237
+
238
+ transfer(1, 2, 50); // BEGIN, run, COMMIT; ROLLBACK if it throws
239
+ transfer.immediate(1, 2, 50); // BEGIN IMMEDIATE
240
+ ```
241
+
242
+ The wrapper commits when the callback returns and rolls back (and rethrows) when it throws. Called while a transaction is already open, it uses a savepoint, so a nested failure undoes only its own part. `.deferred(...)`, `.immediate(...)` and `.exclusive(...)` pick the `BEGIN` mode; calling the wrapper directly is `BEGIN` (deferred). The callback must be synchronous: one that returns a promise is rolled back and throws.
243
+
244
+ ### Errors
245
+
246
+ Every failure SQLite reports is a `sqlite.error` (alias `sqlite.err`):
247
+
248
+ ```js
249
+ try {
250
+ db.prepare("INSERT INTO note (id, body) VALUES (1, 'x')").run();
251
+ } catch (thrown) {
252
+ if (thrown instanceof sqlite.error) {
253
+ thrown.code; // "SQLITE_CONSTRAINT_PRIMARYKEY"
254
+ thrown.number; // 1555, the extended result code
255
+ thrown.sql; // the statement, when the failure came from one
256
+ }
257
+ }
258
+ ```
259
+
260
+ Argument mistakes are plain `TypeError`s and `RangeError`s. `sqlite.error` is one class across every entry, so an error thrown through `@cldmv/sqlite-wasm/worker` (where it is also `client.error`) or the Drizzle driver is an `instanceof sqlite.error` too.
261
+
262
+ ### Aliases
263
+
264
+ | Name | Alias |
265
+ | -------------------------------------------------- | ------------ |
266
+ | `db.execute` | `db.exec` |
267
+ | `db.prepare` | `db.prep` |
268
+ | `db.transaction` | `db.tx` |
269
+ | `db.fn.aggregate` | `db.fn.agg` |
270
+ | `db.checkpoint` | `db.ckpt` |
271
+ | `statement.iterate` (also `statement.raw.iterate`) | `iter` |
272
+ | `statement.columns` | `cols` |
273
+ | `sqlite.error` | `sqlite.err` |
274
+
275
+ ## Storage and journal modes
276
+
277
+ ### Storage
278
+
279
+ | `storage` | Where | Notes |
280
+ | ------------------ | ------------------------------------------ | ------------------------------------------------------------------------------------------- |
281
+ | `"fs"` | Real files, through synchronous `fs` calls | Node. `fsync` on the file, and on the directory after create and delete. |
282
+ | `"opfs"` | The origin private file system | Dedicated browser workers only. No COOP/COEP headers needed. |
283
+ | `"memory"` | A growable buffer per file name | Any environment. The data lives for the process, so reopening the same name finds it again. |
284
+ | `"auto"` (default) | `fs` in Node, `opfs` in a dedicated worker | Throws on a browser main thread, in shared workers and in service workers. |
285
+
286
+ The OPFS driver gets its synchronous handles before SQLite needs them: `open()` takes the database's Web Lock and opens handles for the database, its `-journal` and its `-wal`, and `attach()` does the same for the extra file. Temp files live in memory (`SQLITE_TEMP_STORE=3`). A second tab opening the same database waits up to `timeout` for the first to let go and then fails with `SQLITE_BUSY`; `timeout: 0` fails at once.
287
+
288
+ ### Journal modes
289
+
290
+ ```js
291
+ await sqlite.open("app.sqlite3", { journal: "wal", sync: "normal" }); // the defaults
292
+ ```
293
+
294
+ | `journal` | Behavior |
295
+ | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
296
+ | `"wal"` (default) | Write-ahead log with `PRAGMA locking_mode = EXCLUSIVE` and `synchronous = NORMAL`. |
297
+ | `"truncate"` | Rollback journal that is truncated instead of deleted at the end of each transaction. The faster rollback mode on OPFS, since it avoids creating and deleting the journal file for every commit. |
298
+ | `"delete"` | Rollback journal that is deleted at the end of each transaction. |
299
+
300
+ WAL is the default because it is faster for most workloads and keeps readers out of the writer's way. SQLite normally needs a shared-memory index (`-shm`) for WAL, and there is no shared memory between wasm instances, processes or tabs. Exclusive locking mode makes SQLite keep that index in heap memory instead, which fits the model here: one connection owns a database and everything else goes through it. The consequence is that no other connection can use a WAL database while it is open here. Rollback modes switch back to normal locking, so locks are released between transactions.
301
+
302
+ The files stay standard SQLite. A clean `close()` checkpoints the WAL and removes the `-wal` file, after which native SQLite and `node:sqlite` open the database as usual. A file left in WAL mode (for example after a crash) opens here and recovers.
303
+
304
+ Use `sync: "full"` if every commit has to be synced.
305
+
306
+ ## Locking
307
+
308
+ One connection owns a database at a time. Several processes (or tabs) writing the same file at once is not supported; the lock keeps them out.
309
+
310
+ ### Node
311
+
312
+ Node has no `fcntl` locks, so opening a database takes an owner lock that lives outside the database file. A second process that opens the same database waits up to `timeout` milliseconds and then fails with `SQLITE_BUSY`. A lock whose process is gone (same host) is stale and is taken over. The `lock` option picks where it lives:
313
+
314
+ | `lock` | Where | Keeps two processes from writing at once? |
315
+ | -------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
316
+ | `"beside"` (default) | A `<db>.lock/` folder next to the database | Yes. Also across machines on a shared folder, though a crashed remote owner's lock is removed by hand. |
317
+ | `"temp"` | `<os.tmpdir()>/cldmv-sqlite-locks-<uid>/<sha256 of the real path>/` | Yes, for one user on one machine. The folder is private to the user (mode 0700); opening refuses it if it is a symlink, owned by someone else, or writable by others. Other users, and a different `TMPDIR`, do not see these locks. |
318
+ | a folder path | `<folder>/<sha256 of the real path>/` | Yes, for every process that uses the same folder. |
319
+ | `"db"` | A row in a `_cldmv_lock` table inside the database (pid, host, started) | Detects, does not prevent. Opening refuses with `SQLITE_BUSY` if the row names a live process on this host, but two processes opening in the same instant can both get through. A read-only open only checks and never writes. |
320
+
321
+ `"beside"` falls back to `"temp"` when the lock folder cannot be created (a read-only database in a folder you cannot write), so read-only databases in read-only folders still open, protected. The folder kinds hash the file's real path, so two paths to one file (a symlink, `..`) share one lock. `db.info.lock` reports what is in effect.
322
+
323
+ Native SQLite does not know about these locks. Opening the same file with native SQLite while this library has it open is not supported; opening it before or after is.
324
+
325
+ ### Browsers
326
+
327
+ The browser always uses the real lock: a Web Lock per database plus the browsers' own exclusive sync access handles. The `lock` option is ignored. `db.info.lock` is `"web"`.
328
+
329
+ ## Browser: worker and host
330
+
331
+ The worker pair is one file on each side.
332
+
333
+ ```js
334
+ // db-worker.mjs
335
+ import host from "@cldmv/sqlite-wasm/host";
336
+
337
+ host.listen(self, {
338
+ // Optional. Runs after each open with the full synchronous API.
339
+ setup(db) {
340
+ db.fn.scalar("slug", (text) => text.toLowerCase().replaceAll(" ", "-"), { deterministic: true });
341
+ }
342
+ });
343
+ ```
344
+
345
+ ```js
346
+ // page
347
+ import client from "@cldmv/sqlite-wasm/worker";
348
+
349
+ const db = await client.connect(new URL("./db-worker.mjs", import.meta.url), "app.sqlite3", {
350
+ journal: "wal"
351
+ });
352
+ ```
353
+
354
+ `client.connect(target, path, options?)` takes a worker script URL (a module worker is started, and terminated on `close()`), or a `Worker` or `MessagePort` that already runs the host. The options are `sqlite.open()`'s except that `storage` is `"opfs"` (the default) or `"memory"` and there is no `lock`; `share` is covered [below](#multi-tab-sharing).
355
+
356
+ `host.listen(scope, options?)` takes:
357
+
358
+ | Option | Description |
359
+ | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
360
+ | `wasm` | Where `sqlite3.wasm` comes from: a URL, bytes, a `Response` or a compiled module. By default the package's own file next to the bundle. Bundlers that understand `new URL("./sqlite3.wasm", import.meta.url)` (Vite, webpack, Parcel) emit it as an asset; otherwise pass its URL. |
361
+ | `setup(db)` | Runs after each open with the synchronous `database`. Register functions and collations here, since they run in the worker. A throw fails the open. |
362
+ | `root` | The OPFS directory databases live in; `navigator.storage.getDirectory()` by default. |
363
+ | `locks` | The Web Locks manager; `navigator.locks` by default. `null` relies on the exclusive sync handles alone. |
364
+ | `wait` | Milliseconds to wait for another tab to close the database; defaults to `timeout`. |
365
+
366
+ The client has the same surface as the synchronous API, with every call returning a promise: `prepare`/`prep`, `execute`/`exec`, `pragma`, `transaction`/`tx`, `attach`, `detach`, `backup`, `serialize`, `checkpoint`/`ckpt`, `close`, and `info` (`path`, `storage`, `lock`, `open`, `transaction`). Statements have `run`, `get`, `all`, `iterate` (async iterators), `raw`, `pluck`, `expand`, `bind`, `columns` and `close`.
367
+
368
+ A few things differ:
369
+
370
+ - `db.fn.*` throws on the client. Register functions in the host's `setup(db)`.
371
+ - A `transaction()` callback receives `tx`, whose `prepare`, `execute` and `pragma` join the transaction. Calls made without awaiting in between go out as one batch, and a callback that never awaits mid-way costs a single message. A transaction started inside another becomes a savepoint, so a failure there undoes only the savepoint.
372
+ - Calls made in the same tick travel as one message, and the host runs neighbouring independent statements inside one transaction so they share a single OPFS commit. Every call still gets its own result or error.
373
+ - `db.backup(target, { schema }?)` writes into the worker's storage, and `db.serialize()` transfers the bytes from the worker.
374
+ - `db.proxy(sql, params, method)` is a Drizzle `sqlite-proxy` callback over the connection.
375
+
376
+ Using a database from the main thread only for tests or scratch work is fine with `storage: "memory"`, since OPFS is not available there.
377
+
378
+ ## Multi-tab sharing
379
+
380
+ Several tabs of the same origin can use one OPFS database at once. One tab owns it and the others go through that tab; ownership moves on its own when the owner closes or its worker ends.
381
+
382
+ ```js
383
+ const db = await client.connect(new URL("./db-worker.mjs", import.meta.url), "app.sqlite3", { share: true });
384
+
385
+ db.info.leader; // true if this tab's worker holds the database
386
+ const stop = db.info.watch((leader) => console.log("leader:", leader));
387
+ ```
388
+
389
+ How it works: every tab that connects asks for the Web Lock `sqlite:<path>:leader` and waits. The holder is the leader, and its dedicated worker opens the database. The other tabs are followers: they send requests to the leader over a `BroadcastChannel` named `sqlite:<path>`, and the leader runs them in its worker and broadcasts the answers. The browser releases the lock when the leader's tab dies, and the next waiting tab becomes the leader with no stale state. The API is the same in every tab; `db.info.leader` and `db.info.watch(listener)` (which returns a function that stops it) are the only differences.
390
+
391
+ Guarantees:
392
+
393
+ - Requests from one tab run in the order that tab sent them. Between tabs the order is whatever order they reach the leader.
394
+ - A transaction from any tab runs alone. While one tab's transaction is open, other tabs' requests wait for it. If that tab goes away mid-transaction, the leader rolls it back.
395
+ - Reads are retried against the new leader after a handover. A write the old leader never started is retried too. A write whose outcome is unknown, because the old leader began it and then went away, fails with `SQLITE_BUSY` ("the leader changed") rather than running twice. A transaction that began under the old leader is rolled back and its remaining calls reject with `SQLITE_BUSY`.
396
+ - A leader whose worker ends while its tab stays open (the browser killed it, it was terminated, or it threw an uncaught error, after which it is terminated) hands over the same way as if the tab had closed; see [a leader's worker ends](#when-a-leaders-worker-ends).
397
+ - A leader that closes keeps serving until its own earlier calls and any open follower transaction are done, then closes the database and releases the lock. Requests it did not pass on are resent to the next leader.
398
+
399
+ Caveats:
400
+
401
+ - Connection state lives in the leader's worker and does not move at a handover: attached databases, `PRAGMA` settings and functions registered outside the host's `setup` hook are gone in the new leader. Put anything you need to persist in `setup(db)`.
402
+ - Every tab must connect with the same path string, since the lock and channel names are derived from it.
403
+ - `share: true` needs the worker script's URL (not an existing `Worker` or `MessagePort`), because each tab that becomes the leader starts its own worker. It also needs Web Locks, `BroadcastChannel` and `Worker`, so it only works in a browser page.
404
+ - Sharing is between tabs of one origin. Sharing across origins, or with a service worker, is not supported.
405
+
406
+ ### When a leader's worker ends
407
+
408
+ The leader's worker takes a Web Lock (`sqlite:<path>:worker:<id>`) when it starts and never lets it go, and the leader tab waits for that same lock. The browser releases a lock when its owner ends, however it ends, so the lock being granted to the tab means the worker is gone. An uncaught error in the worker counts as well: the tab terminates the worker and handles it the same way.
409
+
410
+ The tab then steps down as if it had closed:
411
+
412
+ - Writes its worker had already started reject with `SQLITE_BUSY` ("the leader changed"), since their outcome is unknown. A transaction that was open fails as rolled back.
413
+ - Reads and calls the worker had not started are resent through the new leader, and so are followers' requests.
414
+ - `db.info.leader` flips to `false` and `watch` listeners fire. The tab releases the leader lock and joins again as a follower under a new tab id, so the other tabs see a new leader even if this tab is elected again.
415
+ - If another tab is waiting, it becomes the leader and starts its own worker. If none is, this tab is elected again and starts a new worker, and `info.leader` goes back to `true`.
416
+
417
+ A worker that ends before the database is open fails the `connect()` with `SQLITE_CANTOPEN`. Connection state does not survive this either: see the first caveat above.
418
+
419
+ ## Drizzle
420
+
421
+ `@cldmv/sqlite-wasm/drizzle` wraps a database for [Drizzle ORM](https://orm.drizzle.team). It needs `drizzle-orm` `^0.45.0` as a peer.
422
+
423
+ ### Synchronous (Node, or inside a worker)
424
+
425
+ ```js
426
+ import sqlite from "@cldmv/sqlite-wasm";
427
+ import { drizzle, migrate } from "@cldmv/sqlite-wasm/drizzle";
428
+ import * as schema from "./schema.js";
429
+
430
+ const db = drizzle(await sqlite.open("app.sqlite3"), { schema });
431
+
432
+ db.select().from(schema.note).all();
433
+ db.transaction((tx) => {
434
+ tx.insert(schema.note).values({ body: "hello" }).run();
435
+ });
436
+ ```
437
+
438
+ This goes through Drizzle's own better-sqlite3 session, so the query API is the one Drizzle documents for better-sqlite3: `.all()`, `.get()`, `.run()`, `.values()` and `db.transaction()` are synchronous. You do not need the native `better-sqlite3` package.
439
+
440
+ ### Asynchronous (browser main thread)
441
+
442
+ ```js
443
+ import client from "@cldmv/sqlite-wasm/worker";
444
+ import { drizzle } from "@cldmv/sqlite-wasm/drizzle";
445
+ import * as schema from "./schema.js";
446
+
447
+ const db = drizzle(await client.connect(new URL("./db-worker.mjs", import.meta.url), "app.sqlite3"), { schema });
448
+
449
+ await db.select().from(schema.note);
450
+ await db.query.note.findMany();
451
+ await db.transaction(async (tx) => {
452
+ await tx.insert(schema.note).values({ body: "hello" });
453
+ });
454
+ await db.batch([db.insert(schema.note).values({ body: "a" }), db.insert(schema.note).values({ body: "b" })]);
455
+ ```
456
+
457
+ A worker client goes through Drizzle's `sqlite-proxy` session. Transactions run through the client's own transaction queue, so concurrent ones do not interleave their `BEGIN` and `COMMIT`, and `db.batch()` runs its queries in one transaction in the worker.
458
+
459
+ `drizzle(db, config?)` takes `schema` (enables `db.query.*`), `logger` (`true` or a Drizzle logger) and `casing` (`"snake_case"` or `"camelCase"`). Drizzle's `cache` option is not supported. The original database or client is on `db.$client`.
460
+
461
+ ### Migrations
462
+
463
+ Drizzle's own `migrate()` from `drizzle-orm/better-sqlite3/migrator` works on the synchronous result. It reads a folder, so it is for Node and workers with a file system. For migrations bundled as data (`{ journal, migrations }`, the shape drizzle-kit writes for its bundled drivers), use the `migrate()` from this package. It works for both kinds of database, so it serves the browser too:
464
+
465
+ ```js
466
+ import { migrate } from "@cldmv/sqlite-wasm/drizzle";
467
+ import journal from "./drizzle/meta/_journal.json" with { type: "json" };
468
+ import m0000 from "./drizzle/0000_init.sql?raw"; // bundler-specific: any way of getting the SQL as a string
469
+
470
+ migrate(db, { journal, migrations: { m0000 } }); // synchronous database
471
+ await migrate(db, { journal, migrations: { m0000 } }); // worker client
472
+ ```
473
+
474
+ Migrations are keyed `m0000`, `m0001`, and so on, matching the journal's `idx`. They run in one transaction.
475
+
476
+ ### Browser caveat: `blob` columns need a `Buffer`
477
+
478
+ Drizzle's `blob` column types call the global `Buffer`: always in `buffer` mode, and when writing in `json` and `bigint` modes. Browsers do not have `Buffer` and Drizzle does not provide it. An app that uses those columns in a browser adds the [`buffer`](https://www.npmjs.com/package/buffer) package and installs it as a global before any query runs:
479
+
480
+ ```js
481
+ import { Buffer } from "buffer";
482
+
483
+ globalThis.Buffer = Buffer;
484
+ ```
485
+
486
+ Install this wherever Drizzle runs: the page for the async client, and the worker too if you use Drizzle there.
487
+
488
+ ## What is compiled in
489
+
490
+ SQLite 3.54.1, built from SQLite's source archive with wasi-sdk 34 and optimized with binaryen. The amalgamation is generated from the archive by SQLite's own scripts (`make sqlite3.c`), with `SQLITE_ENABLE_UPDATE_DELETE_LIMIT` set so the generated parser accepts it. The build includes:
491
+
492
+ - FTS3, FTS4 (built together with FTS3) and FTS5, with `FTS3_PARENTHESIS`
493
+ - R\*Tree and Geopoly
494
+ - JSON functions (built in)
495
+ - the `dbstat` virtual table
496
+ - math functions
497
+ - `percentile` functions
498
+ - column metadata (`stmt.columns()` reports `table`, `column` and `database`)
499
+ - `UPDATE ... ORDER BY ... LIMIT` and `DELETE ... ORDER BY ... LIMIT` (`SQLITE_ENABLE_UPDATE_DELETE_LIMIT`), which Drizzle's `update()` and `delete()` builders use for `.orderBy()` and `.limit()`
500
+ - STAT4 query-planner statistics
501
+
502
+ Defaults:
503
+
504
+ - foreign keys on, `DQS=0` (double-quoted strings are identifiers only; use single quotes for text), `LIKE` does not match BLOBs
505
+ - temp tables and indices in memory (`TEMP_STORE=3`), `synchronous=NORMAL` in WAL mode
506
+ - single-threaded build (`THREADSAFE=0`)
507
+
508
+ Left out: loadable extensions, UTF-16 APIs, shared cache, deprecated interfaces, the progress callback, TCL variables and `sqlite3_get_table`. `localtime` is UTC, because wasi-libc has no time zone database.
509
+
510
+ All connections in a process share one module instance, which is what lets `ATTACH` and `backup()` work between them.
511
+
512
+ ## Requirements
513
+
514
+ - Node.js `>=20.19.0` at runtime (`engines`). The CommonJS entry relies on `require(esm)`, which needs `^20.19.0` or `>=22.13.0`.
515
+ - Working on this repository needs Node.js `>=22.22.0` (`devEngines`).
516
+ - Browsers: a dedicated worker with OPFS sync access handles for persistent storage, and WebAssembly. Multi-tab sharing also needs Web Locks and `BroadcastChannel`.
517
+
518
+ ## Development
519
+
520
+ The source is TypeScript (`src/**/*.mts`) and the package ships built `dist/`. The wasm is built from source by `npm run build` (tsup, then `scripts/build-wasm.mjs`), which downloads pinned versions of SQLite's source archive, wasi-sdk and binaryen into `.cache/toolchains/` (override with `SQLITE_WASM_TOOLCHAIN_DIR`). The pins and hashes are in `sqlite.version.json`, and `npm run sqlite:bump` updates the SQLite pin. Generating the amalgamation needs `make` and a C compiler (`cc`, or `$CC`) on the build machine, which Linux and macOS have; nothing else, since the archive carries its own Tcl interpreter. The built `dist/sqlite3.wasm` is what gets published, so consumers need none of this.
521
+
522
+ To run from `src/` without building, resolve the `sqlite-wasm-dev` export condition, which points every entry at its `.mts` source:
523
+
524
+ ```sh
525
+ node --conditions=sqlite-wasm-dev app.mts
526
+ ```
527
+
528
+ (The wasm itself still has to be built once.)
529
+
530
+ Useful scripts: `npm run build`, `npm test` (Node tests, the CommonJS tests and the same tests against `dist/`), `npm run test:browser` (Chromium), `npm run coverage`, `npm run lint`, `npm run format`, `npm run types:check`.
531
+
532
+ [![CodeFactor]][codefactor_url] [![OpenSSF Scorecard]][ossf_scorecard_url] [![npms.io score]][npms_url] [![npm unpacked size]][npm_size_url] [![Repo size]][repo_size_url]
533
+
534
+ ## License
535
+
536
+ [![GitHub license]][github_license_url] [![npm license]][npm_license_url]
537
+
538
+ [Apache-2.0](LICENSE) © Shinrai / CLDMV
539
+
540
+ [npm version]: https://img.shields.io/npm/v/%40cldmv%2Fsqlite-wasm.svg?style=for-the-badge&logo=npm&logoColor=white&labelColor=CB3837
541
+ [npm_version_url]: https://www.npmjs.com/package/@cldmv/sqlite-wasm
542
+ [last commit]: https://img.shields.io/github/last-commit/CLDMV/lib-sqlite-wasm?style=for-the-badge&logo=github&logoColor=white&labelColor=181717
543
+ [last_commit_url]: https://github.com/CLDMV/lib-sqlite-wasm/commits
544
+ [npm last update]: https://img.shields.io/npm/last-update/%40cldmv%2Fsqlite-wasm?style=for-the-badge&logo=npm&logoColor=white&labelColor=CB3837
545
+ [npm_last_update_url]: https://www.npmjs.com/package/@cldmv/sqlite-wasm
546
+ [codefactor]: https://img.shields.io/codefactor/grade/github/CLDMV/lib-sqlite-wasm?style=for-the-badge&logo=codefactor&logoColor=white&labelColor=F44A6A
547
+ [codefactor_url]: https://www.codefactor.io/repository/github/cldmv/lib-sqlite-wasm
548
+ [openssf scorecard]: https://img.shields.io/ossf-scorecard/github.com/CLDMV/lib-sqlite-wasm?style=for-the-badge&label=OpenSSF%20Scorecard
549
+ [ossf_scorecard_url]: https://scorecard.dev/viewer/?uri=github.com/CLDMV/lib-sqlite-wasm
550
+ [npms.io score]: https://img.shields.io/npms-io/final-score/%40cldmv%2Fsqlite-wasm?style=for-the-badge&logo=npms&logoColor=white&labelColor=0B5D57
551
+ [npms_url]: https://npms.io/search?q=%40cldmv%2Fsqlite-wasm
552
+ [npm downloads]: https://img.shields.io/npm/dm/%40cldmv%2Fsqlite-wasm.svg?style=for-the-badge&logo=npm&logoColor=white&labelColor=CB3837
553
+ [npm_downloads_url]: https://www.npmjs.com/package/@cldmv/sqlite-wasm
554
+ [github downloads]: https://img.shields.io/github/downloads/CLDMV/lib-sqlite-wasm/total?style=for-the-badge&logo=github&logoColor=white&labelColor=181717
555
+ [github_downloads_url]: https://github.com/CLDMV/lib-sqlite-wasm/releases
556
+ [npm unpacked size]: https://img.shields.io/npm/unpacked-size/%40cldmv%2Fsqlite-wasm.svg?style=for-the-badge&logo=npm&logoColor=white&labelColor=CB3837
557
+ [npm_size_url]: https://www.npmjs.com/package/@cldmv/sqlite-wasm
558
+ [repo size]: https://img.shields.io/github/repo-size/CLDMV/lib-sqlite-wasm?style=for-the-badge&logo=github&logoColor=white&labelColor=181717
559
+ [repo_size_url]: https://github.com/CLDMV/lib-sqlite-wasm
560
+ [github license]: https://img.shields.io/github/license/CLDMV/lib-sqlite-wasm.svg?style=for-the-badge&logo=github&logoColor=white&labelColor=181717
561
+ [github_license_url]: https://github.com/CLDMV/lib-sqlite-wasm/blob/HEAD/LICENSE
562
+ [npm license]: https://img.shields.io/npm/l/%40cldmv%2Fsqlite-wasm.svg?style=for-the-badge&logo=npm&logoColor=white&labelColor=CB3837
563
+ [npm_license_url]: https://www.npmjs.com/package/@cldmv/sqlite-wasm
564
+ [coverage]: https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2FCLDMV%2Flib-sqlite-wasm%2Fbadges%2Fcoverage.json&style=for-the-badge&logo=vitest&logoColor=white
565
+ [coverage_url]: https://github.com/CLDMV/lib-sqlite-wasm/blob/badges/coverage.json
566
+ [contributors]: https://img.shields.io/github/contributors/CLDMV/lib-sqlite-wasm.svg?style=for-the-badge&logo=github&logoColor=white&labelColor=181717
567
+ [contributors_url]: https://github.com/CLDMV/lib-sqlite-wasm/graphs/contributors
568
+ [sponsor shinrai]: https://img.shields.io/github/sponsors/shinrai?style=for-the-badge&logo=githubsponsors&logoColor=white&labelColor=EA4AAA&label=Sponsor
569
+ [sponsor_url]: https://github.com/sponsors/shinrai
@@ -0,0 +1,2 @@
1
+ import{a,b as i}from"./chunk-VOHQWANF.mjs";import{a as t}from"./chunk-IRDSVJEM.mjs";function m(e,n){if(!(e instanceof Error))return{name:"Error",message:String(e)};let r=e;if(typeof r.number!="number")return{name:e.name,message:e.message};let o=typeof r.sql=="string"?r.sql:n,s={name:"sqlite.error",message:e.message,code:a(r.number),number:r.number};return o!==void 0&&(s.sql=o),s}t(m,"serialize");function u(e){if(e.number!==void 0)return new i(e.message,e.number,e.sql);let n=new Error(e.message);return n.name=e.name,n}t(u,"revive");export{m as a,u as b};
2
+ //# sourceMappingURL=chunk-IEYL6MVW.mjs.map
@@ -0,0 +1,2 @@
1
+ var d=Object.defineProperty;var e=(b,a)=>d(b,"name",{value:a,configurable:!0});var f=(b,a)=>{for(var c in a)d(b,c,{get:a[c],enumerable:!0})};export{e as a,f as b};
2
+ //# sourceMappingURL=chunk-IRDSVJEM.mjs.map
@@ -0,0 +1,2 @@
1
+ import{a as l}from"./chunk-IRDSVJEM.mjs";var o=class{static{l(this,"MemoryDriver")}#e=new Map;#r=new Map;files(){return[...this.#e.keys()]}contents(n){let e=this.#e.get(n);return e&&e.data.slice(0,e.size)}#n(n){let e=this.#r.get(n);if(!e)throw new Error(`memory driver: no open file with id ${n}`);return e}open(n,e,r){let t=n??`temp-${e}`,s=this.#e.get(t);if(!s){if(!(r&4))return 14;s={data:new Uint8Array(0),size:0,locks:new Map},this.#e.set(t,s)}return s.locks.set(e,0),this.#r.set(e,{name:t,file:s,deleteOnClose:n===null||(r&8)!==0}),0}delete(n){return this.#e.delete(n)?0:5898}access(n){return this.#e.has(n)}fullPathname(n){return n}read(n,e,r){let{file:t}=this.#n(n),s=Math.max(0,Math.min(e.length,t.size-r));return e.set(t.data.subarray(r,r+s)),s===e.length?0:(e.fill(0,s),522)}write(n,e,r){let{file:t}=this.#n(n),s=r+e.length;if(s>t.data.length){let a=new Uint8Array(Math.max(s,t.data.length*2));a.set(t.data.subarray(0,t.size)),t.data=a}return t.data.set(e,r),t.size=Math.max(t.size,s),0}truncate(n,e){let{file:r}=this.#n(n);return e<r.size&&(r.data.fill(0,e,r.size),r.size=e),0}sync(){return 0}size(n){return this.#n(n).file.size}lock(n,e){let{file:r}=this.#n(n);for(let[t,s]of r.locks){if(t===n)continue;if(e===1?s>=3:e===2?s>=2:s>0)return 5}return r.locks.set(n,e),0}unlock(n,e){return this.#n(n).file.locks.set(n,e),0}checkReserved(n){let{file:e}=this.#n(n);for(let[r,t]of e.locks)if(r!==n&&t>=2)return!0;return!1}close(n){let e=this.#n(n);return e.file.locks.delete(n),this.#r.delete(n),e.deleteOnClose&&this.#e.get(e.name)===e.file&&this.#e.delete(e.name),0}sectorSize(){return 4096}deviceCharacteristics(){return 4608}};export{o as a};
2
+ //# sourceMappingURL=chunk-IXZKMCUU.mjs.map
@@ -0,0 +1,2 @@
1
+ import{a as R}from"./chunk-IRDSVJEM.mjs";var L={0:"OK",1:"ERROR",2:"INTERNAL",3:"PERM",4:"ABORT",5:"BUSY",6:"LOCKED",7:"NOMEM",8:"READONLY",9:"INTERRUPT",10:"IOERR",11:"CORRUPT",12:"NOTFOUND",13:"FULL",14:"CANTOPEN",15:"PROTOCOL",16:"EMPTY",17:"SCHEMA",18:"TOOBIG",19:"CONSTRAINT",20:"MISMATCH",21:"MISUSE",22:"NOLFS",23:"AUTH",24:"FORMAT",25:"RANGE",26:"NOTADB",27:"NOTICE",28:"WARNING",100:"ROW",101:"DONE"},S={OK:["LOAD_PERMANENTLY","SYMLINK"],ERROR:["MISSING_COLLSEQ","RETRY","SNAPSHOT","RESERVESIZE","KEY","UNABLE"],IOERR:["READ","SHORT_READ","WRITE","FSYNC","DIR_FSYNC","TRUNCATE","FSTAT","UNLOCK","RDLOCK","DELETE","BLOCKED","NOMEM","ACCESS","CHECKRESERVEDLOCK","LOCK","CLOSE","DIR_CLOSE","SHMOPEN","SHMSIZE","SHMLOCK","SHMMAP","SEEK","DELETE_NOENT","MMAP","GETTEMPPATH","CONVPATH","VNODE","AUTH","BEGIN_ATOMIC","COMMIT_ATOMIC","ROLLBACK_ATOMIC","DATA","CORRUPTFS","IN_PAGE","BADKEY","CODEC"],LOCKED:["SHAREDCACHE","VTAB"],BUSY:["RECOVERY","SNAPSHOT","TIMEOUT"],CANTOPEN:["NOTEMPDIR","ISDIR","FULLPATH","CONVPATH","DIRTYWAL","SYMLINK"],CORRUPT:["VTAB","SEQUENCE","INDEX"],READONLY:["RECOVERY","CANTLOCK","ROLLBACK","DBMOVED","CANTINIT","DIRECTORY"],ABORT:["","ROLLBACK"],CONSTRAINT:["CHECK","COMMITHOOK","FOREIGNKEY","FUNCTION","NOTNULL","PRIMARYKEY","TRIGGER","UNIQUE","VTAB","ROWID","PINNED","DATATYPE"],NOTICE:["RECOVER_WAL","RECOVER_ROLLBACK","RBU"],WARNING:["AUTOINDEX"],AUTH:["USER"]};function N(T){let E=L[T&255]??"UNKNOWN",O=S[E]?.[(T>>8)-1];return O?`SQLITE_${E}_${O}`:`SQLITE_${E}`}R(N,"codeName");var A=class extends Error{static{R(this,"error")}code;number;sql;constructor(E,O,C,I){super(E,I),this.name="sqlite.error",this.code=N(O),this.number=O,this.sql=C}};export{N as a,A as b};
2
+ //# sourceMappingURL=chunk-VOHQWANF.mjs.map