@statewalker/db-sqlite-browser 0.2.0 → 0.2.2

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 CHANGED
@@ -24,9 +24,10 @@ pnpm add @statewalker/db-sqlite-browser
24
24
  | --- | --- | --- |
25
25
  | `@statewalker/db-sqlite-browser` | `newBrowserSqliteDb`; types `BrowserDbOptions`, `Db`, `DbEntry`, `DbOptions` | browser: main thread (in-memory) or Dedicated Worker (OPFS); Node.js (in-memory) |
26
26
 
27
- `newBrowserSqliteDb({ path?, wasmUrl? })` returns `Promise<Db>`. Without `path` the database is
28
- in memory; that also works under Node.js (where a `wasmUrl`, if given, is a file path). With
29
- `path` it lives in OPFS through the `opfs-sahpool` VFS, which works only in a Dedicated Worker.
27
+ `newBrowserSqliteDb({ path?, wasmUrl?, capacity? })` returns `Promise<Db>`. Without `path` the
28
+ database is in memory; that also works under Node.js (where a `wasmUrl`, if given, is a file path).
29
+ With `path` it lives in OPFS through the `opfs-sahpool` VFS, which works only in a Dedicated Worker.
30
+ `capacity` raises the number of files that VFS can hold (see below).
30
31
  Use `?` placeholders. Bundlers must not pre-bundle `@sqlite.org/sqlite-wasm` (Vite:
31
32
  `optimizeDeps.exclude`), or pass `wasmUrl`.
32
33
 
@@ -41,6 +42,32 @@ await db.exec("CREATE VIRTUAL TABLE IF NOT EXISTS notes USING fts5(body)");
41
42
  const hits = await db.query("SELECT rowid FROM notes WHERE notes MATCH ?", ["sqlite"]);
42
43
  ```
43
44
 
45
+ ```ts
46
+ // A worker that keeps one database per project: reserve room before the default 6 files run out.
47
+ const projectId = "p1";
48
+ const db = await newBrowserSqliteDb({ path: `/projects/${projectId}.db`, capacity: 64 });
49
+ ```
50
+
51
+ ## How many databases fit: the pool holds a fixed number of files
52
+
53
+ `opfs-sahpool` keeps a pool of OPFS files open for as long as the worker lives, and every file
54
+ SQLite creates takes one: each database file, whether open or closed, and its rollback journal
55
+ while a write transaction runs. The pool starts with **6** files, so a worker can keep about
56
+ five databases if their writes do not overlap.
57
+
58
+ - **What a full pool looks like.** Creating a database, or the journal of its next write, fails with
59
+ `SQLITE_CANTOPEN: sqlite3 result code 14: unable to open database file`. It looks like a bad path
60
+ or a locking problem, but it is the pool running out of files. Opening a database that already
61
+ exists needs no new file.
62
+ - **`capacity` reserves room.** It is the minimum number of files in the pool. It is stored in OPFS
63
+ with the pool, never shrinks, and costs one open file handle per slot from the moment the worker
64
+ starts, used or not, which is why the default is small. Size it at about two files per database
65
+ (the database and its journal), plus a few spare; tens are cheap, hundreds slow the start.
66
+ - **Closing a database does not free its file.** The data stays in the pool until the file is
67
+ deleted, and this driver does not delete files.
68
+ - **One pool per worker.** All databases a worker opens share the pool, and `capacity` applies to
69
+ that pool. Each call that passes `capacity` grows it if needed.
70
+
44
71
  ## Internals
45
72
 
46
73
  - **Why OPFS only in a Dedicated Worker.** `opfs-sahpool` uses synchronous OPFS access handles,
@@ -50,8 +77,6 @@ const hits = await db.query("SELECT rowid FROM notes WHERE notes MATCH ?", ["sql
50
77
  - **One worker owns a database.** The pool holds its OPFS files open while the worker lives; a
51
78
  second worker (or tab) opening the same `path` fails with an OPFS lock error until the first
52
79
  one is terminated.
53
- - **The pool has room for a few files.** Its default capacity is 6 files, and each database also
54
- uses journal files, so a worker that opens many databases can run out of slots.
55
80
  - **Calls are queued** and transactions open with `BEGIN IMMEDIATE` (see `@statewalker/db-sqlite`).
56
81
  Rows are plain objects; BLOBs are `Uint8Array`.
57
82
  - **The engine loads once per `wasmUrl`.** A failed load (for example a wrong `wasmUrl`) is not
package/dist/index.d.mts CHANGED
@@ -3,12 +3,18 @@ import { Db, Db as Db$1, DbEntry, DbOptions, DbOptions as DbOptions$1 } from "@s
3
3
  type BrowserDbOptions = DbOptions$1 & {
4
4
  /** URL of `sqlite3.wasm`. Default: the package's own file, located by the bundler. */
5
5
  wasmUrl?: string;
6
+ /**
7
+ * Minimum number of files the OPFS pool can hold, when `path` is set. Each open database takes
8
+ * one file and its rollback journal another while it writes. Default: the pool's own (6).
9
+ */
10
+ capacity?: number;
6
11
  };
7
12
  /**
8
13
  * Create a SQLite {@link Db} on `@sqlite.org/sqlite-wasm`.
9
14
  *
10
15
  * @param options.path OPFS database name; Dedicated Worker only. Omit for in-memory.
11
16
  * @param options.wasmUrl URL of `sqlite3.wasm`, when the bundler cannot locate it.
17
+ * @param options.capacity Minimum OPFS pool size in files, with `path`; it only ever grows.
12
18
  */
13
19
  export declare function newBrowserSqliteDb(options?: BrowserDbOptions): Promise<Db$1>;
14
20
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":["DbOptions","Db"],"sources":["../src/browser-sqlite-db.ts"],"mappings":";;KASY,mBAAmBA;;EAE7B;;;;;;;;wBA4CoB,mBAAmB,UAAU,mBAAmB,QAAQC"}
1
+ {"version":3,"file":"index.d.mts","names":["DbOptions","Db"],"sources":["../src/browser-sqlite-db.ts"],"mappings":";;KASY,mBAAmBA;;EAE7B;;;;;EAKA;;;;;;;;;wBAuDoB,mBAAmB,UAAU,mBAAmB,QAAQC"}
package/dist/index.mjs CHANGED
@@ -22,17 +22,23 @@ function getPool(sqlite3) {
22
22
  }
23
23
  return pool;
24
24
  }
25
+ async function openPooled(sqlite3, path, capacity) {
26
+ const pool = await getPool(sqlite3);
27
+ if (capacity !== void 0) await pool.reserveMinimumCapacity(capacity);
28
+ return new pool.OpfsSAHPoolDb(path);
29
+ }
25
30
  const inDedicatedWorker = () => typeof globalThis.DedicatedWorkerGlobalScope !== "undefined";
26
31
  /**
27
32
  * Create a SQLite {@link Db} on `@sqlite.org/sqlite-wasm`.
28
33
  *
29
34
  * @param options.path OPFS database name; Dedicated Worker only. Omit for in-memory.
30
35
  * @param options.wasmUrl URL of `sqlite3.wasm`, when the bundler cannot locate it.
36
+ * @param options.capacity Minimum OPFS pool size in files, with `path`; it only ever grows.
31
37
  */
32
38
  async function newBrowserSqliteDb(options) {
33
39
  if (options?.path && !inDedicatedWorker()) throw new Error(MAIN_THREAD_PATH);
34
40
  const sqlite3 = await getSqlite3(options?.wasmUrl);
35
- const db = options?.path ? new (await (getPool(sqlite3))).OpfsSAHPoolDb(options.path) : new sqlite3.oo1.DB(":memory:", "c");
41
+ const db = options?.path ? await openPooled(sqlite3, options.path, options.capacity) : new sqlite3.oo1.DB(":memory:", "c");
36
42
  return newSerialisedSqliteDb({
37
43
  all: (sql, params) => db.exec({
38
44
  sql,
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/browser-sqlite-db.ts"],"sourcesContent":["import sqlite3InitModule, {\n type BindableValue,\n type Database,\n type SAHPoolUtil,\n type Sqlite3Static,\n} from \"@sqlite.org/sqlite-wasm\";\nimport type { Db, DbOptions } from \"@statewalker/db-api\";\nimport { newSerialisedSqliteDb } from \"@statewalker/db-sqlite\";\n\nexport type BrowserDbOptions = DbOptions & {\n /** URL of `sqlite3.wasm`. Default: the package's own file, located by the bundler. */\n wasmUrl?: string;\n};\n\nconst MAIN_THREAD_PATH =\n 'newBrowserSqliteDb: { path } needs a Dedicated Worker (the \"opfs-sahpool\" OPFS VFS runs only ' +\n \"there). On the main thread, omit path for an in-memory database.\";\n\ntype InitModule = (module?: { locateFile?: (file: string) => string }) => Promise<Sqlite3Static>;\n\n/** One engine per wasmUrl, started on first use; one OPFS pool per engine. */\nconst engines = new Map<string, Promise<Sqlite3Static>>();\nconst pools = new WeakMap<Sqlite3Static, Promise<SAHPoolUtil>>();\n\nfunction getSqlite3(wasmUrl: string | undefined): Promise<Sqlite3Static> {\n const key = wasmUrl ?? \"\";\n let engine = engines.get(key);\n if (!engine) {\n engine = (sqlite3InitModule as InitModule)(\n wasmUrl ? { locateFile: (file) => (file.endsWith(\".wasm\") ? wasmUrl : file) } : undefined,\n );\n engines.set(key, engine);\n }\n return engine;\n}\n\nfunction getPool(sqlite3: Sqlite3Static): Promise<SAHPoolUtil> {\n let pool = pools.get(sqlite3);\n if (!pool) {\n pool = sqlite3.installOpfsSAHPoolVfs({});\n pools.set(sqlite3, pool);\n }\n return pool;\n}\n\nconst inDedicatedWorker = () =>\n typeof (globalThis as { DedicatedWorkerGlobalScope?: unknown }).DedicatedWorkerGlobalScope !==\n \"undefined\";\n\n/**\n * Create a SQLite {@link Db} on `@sqlite.org/sqlite-wasm`.\n *\n * @param options.path OPFS database name; Dedicated Worker only. Omit for in-memory.\n * @param options.wasmUrl URL of `sqlite3.wasm`, when the bundler cannot locate it.\n */\nexport async function newBrowserSqliteDb(options?: BrowserDbOptions): Promise<Db> {\n if (options?.path && !inDedicatedWorker()) throw new Error(MAIN_THREAD_PATH);\n const sqlite3 = await getSqlite3(options?.wasmUrl);\n const db: Database = options?.path\n ? new (await getPool(sqlite3)).OpfsSAHPoolDb(options.path)\n : new sqlite3.oo1.DB(\":memory:\", \"c\");\n return newSerialisedSqliteDb({\n all: (sql, params) =>\n db.exec({\n sql,\n bind: params.length > 0 ? (params as BindableValue[]) : undefined,\n rowMode: \"object\",\n returnValue: \"resultRows\",\n }) as Record<string, unknown>[],\n exec: (sql) => {\n db.exec(sql);\n },\n close: () => db.close(),\n });\n}\n"],"mappings":";;;AAcA,MAAM,mBACJ;;AAMF,MAAM,0BAAU,IAAI,IAAoC;AACxD,MAAM,wBAAQ,IAAI,QAA6C;AAE/D,SAAS,WAAW,SAAqD;CACvE,MAAM,MAAM,WAAW;CACvB,IAAI,SAAS,QAAQ,IAAI,GAAG;CAC5B,IAAI,CAAC,QAAQ;EACX,SAAU,kBACR,UAAU,EAAE,aAAa,SAAU,KAAK,SAAS,OAAO,IAAI,UAAU,KAAM,IAAI,KAAA,CAClF;EACA,QAAQ,IAAI,KAAK,MAAM;CACzB;CACA,OAAO;AACT;AAEA,SAAS,QAAQ,SAA8C;CAC7D,IAAI,OAAO,MAAM,IAAI,OAAO;CAC5B,IAAI,CAAC,MAAM;EACT,OAAO,QAAQ,sBAAsB,CAAC,CAAC;EACvC,MAAM,IAAI,SAAS,IAAI;CACzB;CACA,OAAO;AACT;AAEA,MAAM,0BACJ,OAAQ,WAAwD,+BAChE;;;;;;;AAQF,eAAsB,mBAAmB,SAAyC;CAChF,IAAI,SAAS,QAAQ,CAAC,kBAAkB,GAAG,MAAM,IAAI,MAAM,gBAAgB;CAC3E,MAAM,UAAU,MAAM,WAAW,SAAS,OAAO;CACjD,MAAM,KAAe,SAAS,OAC1B,KAAK,OAAM,QAAQ,OAAO,GAAA,CAAG,cAAc,QAAQ,IAAI,IACvD,IAAI,QAAQ,IAAI,GAAG,YAAY,GAAG;CACtC,OAAO,sBAAsB;EAC3B,MAAM,KAAK,WACT,GAAG,KAAK;GACN;GACA,MAAM,OAAO,SAAS,IAAK,SAA6B,KAAA;GACxD,SAAS;GACT,aAAa;EACf,CAAC;EACH,OAAO,QAAQ;GACb,GAAG,KAAK,GAAG;EACb;EACA,aAAa,GAAG,MAAM;CACxB,CAAC;AACH"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/browser-sqlite-db.ts"],"sourcesContent":["import sqlite3InitModule, {\n type BindableValue,\n type Database,\n type SAHPoolUtil,\n type Sqlite3Static,\n} from \"@sqlite.org/sqlite-wasm\";\nimport type { Db, DbOptions } from \"@statewalker/db-api\";\nimport { newSerialisedSqliteDb } from \"@statewalker/db-sqlite\";\n\nexport type BrowserDbOptions = DbOptions & {\n /** URL of `sqlite3.wasm`. Default: the package's own file, located by the bundler. */\n wasmUrl?: string;\n /**\n * Minimum number of files the OPFS pool can hold, when `path` is set. Each open database takes\n * one file and its rollback journal another while it writes. Default: the pool's own (6).\n */\n capacity?: number;\n};\n\nconst MAIN_THREAD_PATH =\n 'newBrowserSqliteDb: { path } needs a Dedicated Worker (the \"opfs-sahpool\" OPFS VFS runs only ' +\n \"there). On the main thread, omit path for an in-memory database.\";\n\ntype InitModule = (module?: { locateFile?: (file: string) => string }) => Promise<Sqlite3Static>;\n\n/** One engine per wasmUrl, started on first use; one OPFS pool per engine. */\nconst engines = new Map<string, Promise<Sqlite3Static>>();\nconst pools = new WeakMap<Sqlite3Static, Promise<SAHPoolUtil>>();\n\nfunction getSqlite3(wasmUrl: string | undefined): Promise<Sqlite3Static> {\n const key = wasmUrl ?? \"\";\n let engine = engines.get(key);\n if (!engine) {\n engine = (sqlite3InitModule as InitModule)(\n wasmUrl ? { locateFile: (file) => (file.endsWith(\".wasm\") ? wasmUrl : file) } : undefined,\n );\n engines.set(key, engine);\n }\n return engine;\n}\n\nfunction getPool(sqlite3: Sqlite3Static): Promise<SAHPoolUtil> {\n let pool = pools.get(sqlite3);\n if (!pool) {\n pool = sqlite3.installOpfsSAHPoolVfs({});\n pools.set(sqlite3, pool);\n }\n return pool;\n}\n\nasync function openPooled(\n sqlite3: Sqlite3Static,\n path: string,\n capacity: number | undefined,\n): Promise<Database> {\n const pool = await getPool(sqlite3);\n if (capacity !== undefined) await pool.reserveMinimumCapacity(capacity);\n return new pool.OpfsSAHPoolDb(path);\n}\n\nconst inDedicatedWorker = () =>\n typeof (globalThis as { DedicatedWorkerGlobalScope?: unknown }).DedicatedWorkerGlobalScope !==\n \"undefined\";\n\n/**\n * Create a SQLite {@link Db} on `@sqlite.org/sqlite-wasm`.\n *\n * @param options.path OPFS database name; Dedicated Worker only. Omit for in-memory.\n * @param options.wasmUrl URL of `sqlite3.wasm`, when the bundler cannot locate it.\n * @param options.capacity Minimum OPFS pool size in files, with `path`; it only ever grows.\n */\nexport async function newBrowserSqliteDb(options?: BrowserDbOptions): Promise<Db> {\n if (options?.path && !inDedicatedWorker()) throw new Error(MAIN_THREAD_PATH);\n const sqlite3 = await getSqlite3(options?.wasmUrl);\n const db: Database = options?.path\n ? await openPooled(sqlite3, options.path, options.capacity)\n : new sqlite3.oo1.DB(\":memory:\", \"c\");\n return newSerialisedSqliteDb({\n all: (sql, params) =>\n db.exec({\n sql,\n bind: params.length > 0 ? (params as BindableValue[]) : undefined,\n rowMode: \"object\",\n returnValue: \"resultRows\",\n }) as Record<string, unknown>[],\n exec: (sql) => {\n db.exec(sql);\n },\n close: () => db.close(),\n });\n}\n"],"mappings":";;;AAmBA,MAAM,mBACJ;;AAMF,MAAM,0BAAU,IAAI,IAAoC;AACxD,MAAM,wBAAQ,IAAI,QAA6C;AAE/D,SAAS,WAAW,SAAqD;CACvE,MAAM,MAAM,WAAW;CACvB,IAAI,SAAS,QAAQ,IAAI,GAAG;CAC5B,IAAI,CAAC,QAAQ;EACX,SAAU,kBACR,UAAU,EAAE,aAAa,SAAU,KAAK,SAAS,OAAO,IAAI,UAAU,KAAM,IAAI,KAAA,CAClF;EACA,QAAQ,IAAI,KAAK,MAAM;CACzB;CACA,OAAO;AACT;AAEA,SAAS,QAAQ,SAA8C;CAC7D,IAAI,OAAO,MAAM,IAAI,OAAO;CAC5B,IAAI,CAAC,MAAM;EACT,OAAO,QAAQ,sBAAsB,CAAC,CAAC;EACvC,MAAM,IAAI,SAAS,IAAI;CACzB;CACA,OAAO;AACT;AAEA,eAAe,WACb,SACA,MACA,UACmB;CACnB,MAAM,OAAO,MAAM,QAAQ,OAAO;CAClC,IAAI,aAAa,KAAA,GAAW,MAAM,KAAK,uBAAuB,QAAQ;CACtE,OAAO,IAAI,KAAK,cAAc,IAAI;AACpC;AAEA,MAAM,0BACJ,OAAQ,WAAwD,+BAChE;;;;;;;;AASF,eAAsB,mBAAmB,SAAyC;CAChF,IAAI,SAAS,QAAQ,CAAC,kBAAkB,GAAG,MAAM,IAAI,MAAM,gBAAgB;CAC3E,MAAM,UAAU,MAAM,WAAW,SAAS,OAAO;CACjD,MAAM,KAAe,SAAS,OAC1B,MAAM,WAAW,SAAS,QAAQ,MAAM,QAAQ,QAAQ,IACxD,IAAI,QAAQ,IAAI,GAAG,YAAY,GAAG;CACtC,OAAO,sBAAsB;EAC3B,MAAM,KAAK,WACT,GAAG,KAAK;GACN;GACA,MAAM,OAAO,SAAS,IAAK,SAA6B,KAAA;GACxD,SAAS;GACT,aAAa;EACf,CAAC;EACH,OAAO,QAAQ;GACb,GAAG,KAAK,GAAG;EACb;EACA,aAAa,GAAG,MAAM;CACxB,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statewalker/db-sqlite-browser",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "SQLite WASM (@sqlite.org/sqlite-wasm) driver for @statewalker/db-api in the browser: in-memory anywhere, OPFS persistence in a Dedicated Worker.",
@@ -31,8 +31,8 @@
31
31
  ],
32
32
  "dependencies": {
33
33
  "@sqlite.org/sqlite-wasm": "3.53.0-build1",
34
- "@statewalker/db-sqlite": "^0.1.0",
35
- "@statewalker/db-api": "^0.1.4"
34
+ "@statewalker/db-api": "^0.1.5",
35
+ "@statewalker/db-sqlite": "^0.1.1"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@playwright/test": "^1.63.0",
@@ -43,7 +43,7 @@
43
43
  "rimraf": "^6.1.3",
44
44
  "tsdown": "^0.23.0",
45
45
  "typescript": "^7.0.2",
46
- "vitest": "^5.0.3",
46
+ "vitest": "^4.1.10 || ^5.0.3",
47
47
  "@statewalker/db-tests": "^0.1.1"
48
48
  },
49
49
  "sideEffects": false,
@@ -107,7 +107,11 @@ const WorkerClass = (
107
107
  ).Worker;
108
108
 
109
109
  /** Run one action in a fresh Dedicated Worker, then terminate it (as a page reload would). */
110
- function inWorker(message: { path: string; action: "write" | "count" }): Promise<number> {
110
+ function inWorker(
111
+ message:
112
+ | { path: string; action: "write" | "count" }
113
+ | { path: string; action: "open-many"; files: number; capacity?: number },
114
+ ): Promise<number> {
111
115
  return new Promise((resolve, reject) => {
112
116
  const worker = new WorkerClass(new URL("../test/opfs-test-worker.ts", import.meta.url), {
113
117
  type: "module",
@@ -137,4 +141,19 @@ describe("OPFS persistence (opfs-sahpool)", () => {
137
141
  expect(await inWorker({ path, action: "write" })).toBe(1);
138
142
  expect(await inWorker({ path, action: "count" })).toBe(1);
139
143
  });
144
+
145
+ // Order matters: the pool's capacity is stored in OPFS and only grows, so the default-size
146
+ // case must run before any test raises it. Files stay in the pool after close, so the
147
+ // second case leaves room for the ones the first left behind.
148
+ it("runs out of pool files with the default capacity", async () => {
149
+ const path = `/full-${Date.now()}`;
150
+ await expect(inWorker({ path, action: "open-many", files: 10 })).rejects.toThrow(
151
+ /SQLITE_CANTOPEN/,
152
+ );
153
+ });
154
+
155
+ it("opens more databases once capacity is raised", async () => {
156
+ const path = `/many-${Date.now()}`;
157
+ expect(await inWorker({ path, action: "open-many", files: 10, capacity: 32 })).toBe(10);
158
+ });
140
159
  });
@@ -10,6 +10,11 @@ import { newSerialisedSqliteDb } from "@statewalker/db-sqlite";
10
10
  export type BrowserDbOptions = DbOptions & {
11
11
  /** URL of `sqlite3.wasm`. Default: the package's own file, located by the bundler. */
12
12
  wasmUrl?: string;
13
+ /**
14
+ * Minimum number of files the OPFS pool can hold, when `path` is set. Each open database takes
15
+ * one file and its rollback journal another while it writes. Default: the pool's own (6).
16
+ */
17
+ capacity?: number;
13
18
  };
14
19
 
15
20
  const MAIN_THREAD_PATH =
@@ -43,6 +48,16 @@ function getPool(sqlite3: Sqlite3Static): Promise<SAHPoolUtil> {
43
48
  return pool;
44
49
  }
45
50
 
51
+ async function openPooled(
52
+ sqlite3: Sqlite3Static,
53
+ path: string,
54
+ capacity: number | undefined,
55
+ ): Promise<Database> {
56
+ const pool = await getPool(sqlite3);
57
+ if (capacity !== undefined) await pool.reserveMinimumCapacity(capacity);
58
+ return new pool.OpfsSAHPoolDb(path);
59
+ }
60
+
46
61
  const inDedicatedWorker = () =>
47
62
  typeof (globalThis as { DedicatedWorkerGlobalScope?: unknown }).DedicatedWorkerGlobalScope !==
48
63
  "undefined";
@@ -52,12 +67,13 @@ const inDedicatedWorker = () =>
52
67
  *
53
68
  * @param options.path OPFS database name; Dedicated Worker only. Omit for in-memory.
54
69
  * @param options.wasmUrl URL of `sqlite3.wasm`, when the bundler cannot locate it.
70
+ * @param options.capacity Minimum OPFS pool size in files, with `path`; it only ever grows.
55
71
  */
56
72
  export async function newBrowserSqliteDb(options?: BrowserDbOptions): Promise<Db> {
57
73
  if (options?.path && !inDedicatedWorker()) throw new Error(MAIN_THREAD_PATH);
58
74
  const sqlite3 = await getSqlite3(options?.wasmUrl);
59
75
  const db: Database = options?.path
60
- ? new (await getPool(sqlite3)).OpfsSAHPoolDb(options.path)
76
+ ? await openPooled(sqlite3, options.path, options.capacity)
61
77
  : new sqlite3.oo1.DB(":memory:", "c");
62
78
  return newSerialisedSqliteDb({
63
79
  all: (sql, params) =>