@statewalker/db-duckdb-browser 0.1.3 → 0.1.4
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 +11 -6
- package/dist/index.d.mts +3 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +21 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/browser-duckdb.browser.test.ts +38 -1
- package/src/browser-duckdb.ts +20 -12
package/README.md
CHANGED
|
@@ -27,7 +27,8 @@ pnpm add @statewalker/db-duckdb-browser
|
|
|
27
27
|
`newBrowserDuckDb(options?)` returns `Promise<Db>`.
|
|
28
28
|
|
|
29
29
|
- `options.path`: an OPFS path such as `opfs://app.duckdb`. Omit it for an
|
|
30
|
-
in-memory database.
|
|
30
|
+
in-memory database. If the path cannot be opened, the call rejects with
|
|
31
|
+
`Cannot open DuckDB database "<path>"`; it never falls back to memory.
|
|
31
32
|
- `options.bundles`: same-origin `DuckDBBundles` URLs. Required for OPFS.
|
|
32
33
|
Without it, the bundle is loaded from jsDelivr.
|
|
33
34
|
|
|
@@ -87,13 +88,17 @@ await db.flush?.(); // CHECKPOINT: without it the insert can be lost on reload
|
|
|
87
88
|
on `CHECKPOINT`. Writes not yet checkpointed can be lost on an abrupt
|
|
88
89
|
teardown such as a page reload. On an in-memory database `flush` does
|
|
89
90
|
nothing.
|
|
90
|
-
- **
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
- **No fallback to memory.** If `options.path` is set but `navigator.storage`
|
|
92
|
+
is missing, the call rejects with
|
|
93
|
+
`Cannot open DuckDB database "<path>": OPFS is unavailable`. If opening the
|
|
94
|
+
path throws, the worker is terminated and the call rejects with
|
|
95
|
+
`Cannot open DuckDB database "<path>"`, the engine's error as `cause`. An
|
|
96
|
+
in-memory database is created only when `options.path` is omitted, so data
|
|
97
|
+
is never silently lost on reload.
|
|
94
98
|
- **Rows.** Query results are Arrow tables; the driver copies each row's
|
|
95
99
|
fields into a plain object. Calls with parameters go through
|
|
96
|
-
`conn.prepare(sql)` and `stmt.query(...params)
|
|
100
|
+
`conn.prepare(sql)` and `stmt.query(...params)`, and the statement is closed
|
|
101
|
+
after each call, also when the query fails; calls without parameters use
|
|
97
102
|
`conn.query(sql)`.
|
|
98
103
|
- **Under Node.js** the module imports, but `newBrowserDuckDb()` rejects with
|
|
99
104
|
`Worker is not defined`. Use `@statewalker/db-duckdb-node` there.
|
package/dist/index.d.mts
CHANGED
|
@@ -16,8 +16,9 @@ interface BrowserDuckDbOptions extends DbOptions$1 {
|
|
|
16
16
|
* Create a DuckDB-backed {@link Db} using WebAssembly in the browser.
|
|
17
17
|
*
|
|
18
18
|
* With `options.path` set to an `opfs://` URL **and** self-hosted
|
|
19
|
-
* `options.bundles`, the database persists across reloads on OPFS.
|
|
20
|
-
* runs in-memory.
|
|
19
|
+
* `options.bundles`, the database persists across reloads on OPFS. Without
|
|
20
|
+
* `options.path` it runs in-memory. If `options.path` cannot be opened, the
|
|
21
|
+
* returned promise rejects; it never falls back to an in-memory database.
|
|
21
22
|
*
|
|
22
23
|
* @param options.path `opfs://` path for persistent storage. Omit for in-memory.
|
|
23
24
|
* @param options.bundles Same-origin bundle URLs (required for OPFS).
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":["DbOptions","Db"],"sources":["../src/browser-duckdb.ts"],"mappings":";;;;UAoBiB,6BAA6BA;;;;;;;;EAQ5C,UAAU,OAAO
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["DbOptions","Db"],"sources":["../src/browser-duckdb.ts"],"mappings":";;;;UAoBiB,6BAA6BA;;;;;;;;EAQ5C,UAAU,OAAO;;;;;;;;;;;;;wBAcG,iBAAiB,UAAU,uBAAuB,QAAQC"}
|
package/dist/index.mjs
CHANGED
|
@@ -15,13 +15,16 @@ function arrowToObjects(table) {
|
|
|
15
15
|
* Create a DuckDB-backed {@link Db} using WebAssembly in the browser.
|
|
16
16
|
*
|
|
17
17
|
* With `options.path` set to an `opfs://` URL **and** self-hosted
|
|
18
|
-
* `options.bundles`, the database persists across reloads on OPFS.
|
|
19
|
-
* runs in-memory.
|
|
18
|
+
* `options.bundles`, the database persists across reloads on OPFS. Without
|
|
19
|
+
* `options.path` it runs in-memory. If `options.path` cannot be opened, the
|
|
20
|
+
* returned promise rejects; it never falls back to an in-memory database.
|
|
20
21
|
*
|
|
21
22
|
* @param options.path `opfs://` path for persistent storage. Omit for in-memory.
|
|
22
23
|
* @param options.bundles Same-origin bundle URLs (required for OPFS).
|
|
23
24
|
*/
|
|
24
25
|
async function newBrowserDuckDb(options) {
|
|
26
|
+
const path = options?.path;
|
|
27
|
+
if (path && (typeof navigator === "undefined" || !navigator.storage)) throw new Error(`Cannot open DuckDB database "${path}": OPFS is unavailable`);
|
|
25
28
|
const selfHosted = options?.bundles;
|
|
26
29
|
const bundle = await duckdb.selectBundle(selfHosted ?? duckdb.getJsDelivrBundles());
|
|
27
30
|
let worker;
|
|
@@ -35,24 +38,34 @@ async function newBrowserDuckDb(options) {
|
|
|
35
38
|
const db = new duckdb.AsyncDuckDB(logger, worker);
|
|
36
39
|
await db.instantiate(bundle.mainModule, bundle.pthreadWorker);
|
|
37
40
|
if (blobUrl) URL.revokeObjectURL(blobUrl);
|
|
38
|
-
|
|
39
|
-
if (options?.path && persistent) try {
|
|
41
|
+
if (path) try {
|
|
40
42
|
await db.open({
|
|
41
|
-
path
|
|
43
|
+
path,
|
|
42
44
|
accessMode: duckdb.DuckDBAccessMode.READ_WRITE
|
|
43
45
|
});
|
|
44
|
-
} catch {
|
|
46
|
+
} catch (error) {
|
|
47
|
+
await db.terminate();
|
|
48
|
+
worker.terminate();
|
|
49
|
+
throw new Error(`Cannot open DuckDB database "${path}"`, { cause: error });
|
|
50
|
+
}
|
|
45
51
|
const conn = await db.connect();
|
|
46
52
|
return {
|
|
47
53
|
async query(sql, params) {
|
|
48
|
-
if (params && params.length > 0)
|
|
54
|
+
if (params && params.length > 0) {
|
|
55
|
+
const stmt = await conn.prepare(sql);
|
|
56
|
+
try {
|
|
57
|
+
return arrowToObjects(await stmt.query(...params));
|
|
58
|
+
} finally {
|
|
59
|
+
await stmt.close();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
49
62
|
return arrowToObjects(await conn.query(sql));
|
|
50
63
|
},
|
|
51
64
|
async exec(sql) {
|
|
52
65
|
await conn.query(sql);
|
|
53
66
|
},
|
|
54
67
|
async flush() {
|
|
55
|
-
if (
|
|
68
|
+
if (path) await conn.query("CHECKPOINT");
|
|
56
69
|
},
|
|
57
70
|
async close() {
|
|
58
71
|
await conn.close();
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/browser-duckdb.ts"],"sourcesContent":["import * as duckdb from \"@duckdb/duckdb-wasm\";\nimport type { Db, DbEntry, DbOptions } from \"@statewalker/db-api\";\n\ntype Table = Awaited<ReturnType<duckdb.AsyncPreparedStatement[\"query\"]>>;\n\n/**\n * Convert an Arrow Table (returned by duckdb-wasm queries) to plain JS objects.\n */\nfunction arrowToObjects<T>(table: Table): T[] {\n const fields = table.schema.fields.map((f: { name: string }) => f.name);\n return table.toArray().map((row: Record<string, unknown>) => {\n const obj: Record<string, unknown> = {};\n for (const field of fields) {\n obj[field] = row[field];\n }\n return obj as T;\n });\n}\n\n/** Browser-specific options for {@link newBrowserDuckDb}. */\nexport interface BrowserDuckDbOptions extends DbOptions {\n /**\n * Self-hosted DuckDB bundle URLs (served same-origin, e.g. via a bundler's\n * `?url` import). Passing these makes the factory spawn a **same-origin**\n * worker, which OPFS database persistence requires — a cross-origin worker\n * (the jsDelivr fallback, loaded via a Blob `importScripts` shim) crashes on\n * OPFS file I/O. Omit to load from jsDelivr (in-memory use only).\n */\n bundles?: duckdb.DuckDBBundles;\n}\n\n/**\n * Create a DuckDB-backed {@link Db} using WebAssembly in the browser.\n *\n * With `options.path` set to an `opfs://` URL **and** self-hosted\n * `options.bundles`, the database persists across reloads on OPFS.
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/browser-duckdb.ts"],"sourcesContent":["import * as duckdb from \"@duckdb/duckdb-wasm\";\nimport type { Db, DbEntry, DbOptions } from \"@statewalker/db-api\";\n\ntype Table = Awaited<ReturnType<duckdb.AsyncPreparedStatement[\"query\"]>>;\n\n/**\n * Convert an Arrow Table (returned by duckdb-wasm queries) to plain JS objects.\n */\nfunction arrowToObjects<T>(table: Table): T[] {\n const fields = table.schema.fields.map((f: { name: string }) => f.name);\n return table.toArray().map((row: Record<string, unknown>) => {\n const obj: Record<string, unknown> = {};\n for (const field of fields) {\n obj[field] = row[field];\n }\n return obj as T;\n });\n}\n\n/** Browser-specific options for {@link newBrowserDuckDb}. */\nexport interface BrowserDuckDbOptions extends DbOptions {\n /**\n * Self-hosted DuckDB bundle URLs (served same-origin, e.g. via a bundler's\n * `?url` import). Passing these makes the factory spawn a **same-origin**\n * worker, which OPFS database persistence requires — a cross-origin worker\n * (the jsDelivr fallback, loaded via a Blob `importScripts` shim) crashes on\n * OPFS file I/O. Omit to load from jsDelivr (in-memory use only).\n */\n bundles?: duckdb.DuckDBBundles;\n}\n\n/**\n * Create a DuckDB-backed {@link Db} using WebAssembly in the browser.\n *\n * With `options.path` set to an `opfs://` URL **and** self-hosted\n * `options.bundles`, the database persists across reloads on OPFS. Without\n * `options.path` it runs in-memory. If `options.path` cannot be opened, the\n * returned promise rejects; it never falls back to an in-memory database.\n *\n * @param options.path `opfs://` path for persistent storage. Omit for in-memory.\n * @param options.bundles Same-origin bundle URLs (required for OPFS).\n */\nexport async function newBrowserDuckDb(options?: BrowserDuckDbOptions): Promise<Db> {\n const path = options?.path;\n if (path && (typeof navigator === \"undefined\" || !navigator.storage)) {\n throw new Error(`Cannot open DuckDB database \"${path}\": OPFS is unavailable`);\n }\n const selfHosted = options?.bundles;\n const bundle = await duckdb.selectBundle(selfHosted ?? duckdb.getJsDelivrBundles());\n\n // OPFS file I/O needs a same-origin worker. Self-hosted bundles give a\n // same-origin URL we load directly; the jsDelivr fallback is cross-origin and\n // must be wrapped in a Blob that `importScripts` it.\n let worker: Worker;\n let blobUrl: string | undefined;\n if (selfHosted) {\n worker = new Worker(bundle.mainWorker as string);\n } else {\n blobUrl = URL.createObjectURL(\n new Blob([`importScripts(\"${bundle.mainWorker ?? \"\"}\");`], {\n type: \"text/javascript\",\n }),\n );\n worker = new Worker(blobUrl);\n }\n\n const logger = new duckdb.ConsoleLogger();\n const db = new duckdb.AsyncDuckDB(logger, worker);\n await db.instantiate(bundle.mainModule, bundle.pthreadWorker);\n if (blobUrl) URL.revokeObjectURL(blobUrl);\n\n if (path) {\n try {\n await db.open({\n path,\n accessMode: duckdb.DuckDBAccessMode.READ_WRITE,\n });\n } catch (error) {\n await db.terminate();\n worker.terminate();\n throw new Error(`Cannot open DuckDB database \"${path}\"`, { cause: error });\n }\n }\n\n const conn = await db.connect();\n\n return {\n async query<T = DbEntry>(sql: string, params?: unknown[]): Promise<T[]> {\n if (params && params.length > 0) {\n const stmt = await conn.prepare(sql);\n try {\n const result = await stmt.query(...params);\n return arrowToObjects<T>(result);\n } finally {\n await stmt.close();\n }\n }\n const result = await conn.query(sql);\n return arrowToObjects<T>(result);\n },\n\n async exec(sql: string): Promise<void> {\n await conn.query(sql);\n },\n\n async flush(): Promise<void> {\n // CHECKPOINT writes the WAL into the OPFS database file so committed\n // changes survive a reload. Crucial for OPFS persistence.\n if (path) await conn.query(\"CHECKPOINT\");\n },\n\n async close(): Promise<void> {\n await conn.close();\n await db.terminate();\n worker.terminate();\n },\n };\n}\n"],"mappings":";;;;;AAQA,SAAS,eAAkB,OAAmB;CAC5C,MAAM,SAAS,MAAM,OAAO,OAAO,KAAK,MAAwB,EAAE,IAAI;CACtE,OAAO,MAAM,QAAQ,CAAC,CAAC,KAAK,QAAiC;EAC3D,MAAM,MAA+B,CAAC;EACtC,KAAK,MAAM,SAAS,QAClB,IAAI,SAAS,IAAI;EAEnB,OAAO;CACT,CAAC;AACH;;;;;;;;;;;;AAyBA,eAAsB,iBAAiB,SAA6C;CAClF,MAAM,OAAO,SAAS;CACtB,IAAI,SAAS,OAAO,cAAc,eAAe,CAAC,UAAU,UAC1D,MAAM,IAAI,MAAM,gCAAgC,KAAK,uBAAuB;CAE9E,MAAM,aAAa,SAAS;CAC5B,MAAM,SAAS,MAAM,OAAO,aAAa,cAAc,OAAO,mBAAmB,CAAC;CAKlF,IAAI;CACJ,IAAI;CACJ,IAAI,YACF,SAAS,IAAI,OAAO,OAAO,UAAoB;MAC1C;EACL,UAAU,IAAI,gBACZ,IAAI,KAAK,CAAC,kBAAkB,OAAO,cAAc,GAAG,IAAI,GAAG,EACzD,MAAM,kBACR,CAAC,CACH;EACA,SAAS,IAAI,OAAO,OAAO;CAC7B;CAEA,MAAM,SAAS,IAAI,OAAO,cAAc;CACxC,MAAM,KAAK,IAAI,OAAO,YAAY,QAAQ,MAAM;CAChD,MAAM,GAAG,YAAY,OAAO,YAAY,OAAO,aAAa;CAC5D,IAAI,SAAS,IAAI,gBAAgB,OAAO;CAExC,IAAI,MACF,IAAI;EACF,MAAM,GAAG,KAAK;GACZ;GACA,YAAY,OAAO,iBAAiB;EACtC,CAAC;CACH,SAAS,OAAO;EACd,MAAM,GAAG,UAAU;EACnB,OAAO,UAAU;EACjB,MAAM,IAAI,MAAM,gCAAgC,KAAK,IAAI,EAAE,OAAO,MAAM,CAAC;CAC3E;CAGF,MAAM,OAAO,MAAM,GAAG,QAAQ;CAE9B,OAAO;EACL,MAAM,MAAmB,KAAa,QAAkC;GACtE,IAAI,UAAU,OAAO,SAAS,GAAG;IAC/B,MAAM,OAAO,MAAM,KAAK,QAAQ,GAAG;IACnC,IAAI;KAEF,OAAO,eAAkB,MADJ,KAAK,MAAM,GAAG,MAAM,CACV;IACjC,UAAU;KACR,MAAM,KAAK,MAAM;IACnB;GACF;GAEA,OAAO,eAAkB,MADJ,KAAK,MAAM,GAAG,CACJ;EACjC;EAEA,MAAM,KAAK,KAA4B;GACrC,MAAM,KAAK,MAAM,GAAG;EACtB;EAEA,MAAM,QAAuB;GAG3B,IAAI,MAAM,MAAM,KAAK,MAAM,YAAY;EACzC;EAEA,MAAM,QAAuB;GAC3B,MAAM,KAAK,MAAM;GACjB,MAAM,GAAG,UAAU;GACnB,OAAO,UAAU;EACnB;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import * as duckdb from "@duckdb/duckdb-wasm";
|
|
1
2
|
import type { Db } from "@statewalker/db-api";
|
|
2
3
|
import { runDbConformance } from "@statewalker/db-tests";
|
|
3
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
4
5
|
import { newBrowserDuckDb } from "./browser-duckdb.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -168,4 +169,40 @@ describe("newBrowserDuckDb", () => {
|
|
|
168
169
|
expect(rows[0]?.id).toBe(2);
|
|
169
170
|
});
|
|
170
171
|
});
|
|
172
|
+
|
|
173
|
+
describe("prepared statements", () => {
|
|
174
|
+
afterEach(() => {
|
|
175
|
+
vi.restoreAllMocks();
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("closes the statement of every parameterised query", async () => {
|
|
179
|
+
db = await newBrowserDuckDb();
|
|
180
|
+
const close = vi.spyOn(duckdb.AsyncPreparedStatement.prototype, "close");
|
|
181
|
+
await db.query("SELECT $1::INTEGER AS x", [1]);
|
|
182
|
+
await db.query("SELECT $1::INTEGER AS x", [2]);
|
|
183
|
+
await expect(db.query("SELECT $1::INTEGER AS x", ["not a number"])).rejects.toThrow();
|
|
184
|
+
expect(close).toHaveBeenCalledTimes(3);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe("persistent path", () => {
|
|
189
|
+
afterEach(() => {
|
|
190
|
+
vi.unstubAllGlobals();
|
|
191
|
+
vi.restoreAllMocks();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("rejects instead of falling back to memory when the path cannot be opened", async () => {
|
|
195
|
+
vi.spyOn(duckdb.AsyncDuckDB.prototype, "open").mockRejectedValue(new Error("open failed"));
|
|
196
|
+
await expect(newBrowserDuckDb({ path: "opfs://broken.duckdb" })).rejects.toThrow(
|
|
197
|
+
/opfs:\/\/broken\.duckdb/,
|
|
198
|
+
);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("rejects instead of falling back to memory when OPFS is unavailable", async () => {
|
|
202
|
+
vi.stubGlobal("navigator", {});
|
|
203
|
+
await expect(newBrowserDuckDb({ path: "opfs://unavailable.duckdb" })).rejects.toThrow(
|
|
204
|
+
/opfs:\/\/unavailable\.duckdb/,
|
|
205
|
+
);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
171
208
|
});
|
package/src/browser-duckdb.ts
CHANGED
|
@@ -33,13 +33,18 @@ export interface BrowserDuckDbOptions extends DbOptions {
|
|
|
33
33
|
* Create a DuckDB-backed {@link Db} using WebAssembly in the browser.
|
|
34
34
|
*
|
|
35
35
|
* With `options.path` set to an `opfs://` URL **and** self-hosted
|
|
36
|
-
* `options.bundles`, the database persists across reloads on OPFS.
|
|
37
|
-
* runs in-memory.
|
|
36
|
+
* `options.bundles`, the database persists across reloads on OPFS. Without
|
|
37
|
+
* `options.path` it runs in-memory. If `options.path` cannot be opened, the
|
|
38
|
+
* returned promise rejects; it never falls back to an in-memory database.
|
|
38
39
|
*
|
|
39
40
|
* @param options.path `opfs://` path for persistent storage. Omit for in-memory.
|
|
40
41
|
* @param options.bundles Same-origin bundle URLs (required for OPFS).
|
|
41
42
|
*/
|
|
42
43
|
export async function newBrowserDuckDb(options?: BrowserDuckDbOptions): Promise<Db> {
|
|
44
|
+
const path = options?.path;
|
|
45
|
+
if (path && (typeof navigator === "undefined" || !navigator.storage)) {
|
|
46
|
+
throw new Error(`Cannot open DuckDB database "${path}": OPFS is unavailable`);
|
|
47
|
+
}
|
|
43
48
|
const selfHosted = options?.bundles;
|
|
44
49
|
const bundle = await duckdb.selectBundle(selfHosted ?? duckdb.getJsDelivrBundles());
|
|
45
50
|
|
|
@@ -64,17 +69,16 @@ export async function newBrowserDuckDb(options?: BrowserDuckDbOptions): Promise<
|
|
|
64
69
|
await db.instantiate(bundle.mainModule, bundle.pthreadWorker);
|
|
65
70
|
if (blobUrl) URL.revokeObjectURL(blobUrl);
|
|
66
71
|
|
|
67
|
-
|
|
68
|
-
const persistent =
|
|
69
|
-
Boolean(options?.path) && typeof navigator !== "undefined" && Boolean(navigator.storage);
|
|
70
|
-
if (options?.path && persistent) {
|
|
72
|
+
if (path) {
|
|
71
73
|
try {
|
|
72
74
|
await db.open({
|
|
73
|
-
path
|
|
75
|
+
path,
|
|
74
76
|
accessMode: duckdb.DuckDBAccessMode.READ_WRITE,
|
|
75
77
|
});
|
|
76
|
-
} catch {
|
|
77
|
-
|
|
78
|
+
} catch (error) {
|
|
79
|
+
await db.terminate();
|
|
80
|
+
worker.terminate();
|
|
81
|
+
throw new Error(`Cannot open DuckDB database "${path}"`, { cause: error });
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
|
|
@@ -84,8 +88,12 @@ export async function newBrowserDuckDb(options?: BrowserDuckDbOptions): Promise<
|
|
|
84
88
|
async query<T = DbEntry>(sql: string, params?: unknown[]): Promise<T[]> {
|
|
85
89
|
if (params && params.length > 0) {
|
|
86
90
|
const stmt = await conn.prepare(sql);
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
try {
|
|
92
|
+
const result = await stmt.query(...params);
|
|
93
|
+
return arrowToObjects<T>(result);
|
|
94
|
+
} finally {
|
|
95
|
+
await stmt.close();
|
|
96
|
+
}
|
|
89
97
|
}
|
|
90
98
|
const result = await conn.query(sql);
|
|
91
99
|
return arrowToObjects<T>(result);
|
|
@@ -98,7 +106,7 @@ export async function newBrowserDuckDb(options?: BrowserDuckDbOptions): Promise<
|
|
|
98
106
|
async flush(): Promise<void> {
|
|
99
107
|
// CHECKPOINT writes the WAL into the OPFS database file so committed
|
|
100
108
|
// changes survive a reload. Crucial for OPFS persistence.
|
|
101
|
-
if (
|
|
109
|
+
if (path) await conn.query("CHECKPOINT");
|
|
102
110
|
},
|
|
103
111
|
|
|
104
112
|
async close(): Promise<void> {
|