npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@statewalker/db-sqlite-browser

v0.2.5

Published

SQLite WASM (@sqlite.org/sqlite-wasm) driver for @statewalker/db-api in the browser: in-memory anywhere, OPFS persistence in a Dedicated Worker.

Readme

@statewalker/db-sqlite-browser

What it is

A SQLite driver for the browser that implements Db from @statewalker/db-api on the official WebAssembly build, @sqlite.org/sqlite-wasm (SQLite 3.53, FTS5 with the unicode61, porter and trigram tokenizers). It opens an in-memory database anywhere, and a persistent database in the origin-private file system (OPFS) from a Dedicated Worker. Its Db works with inTransaction from @statewalker/db-sqlite.

Why it exists

It lets code written against Db run on SQLite in the browser with the same SQL as on Node.js (@statewalker/db-sqlite-node) and in Durable Objects (@statewalker/db-sqlite-do), so search and storage code is written and tested once.

How to use

pnpm add @statewalker/db-sqlite-browser

| Import | Gives | Environment | | --- | --- | --- | | @statewalker/db-sqlite-browser | newBrowserSqliteDb; types BrowserDbOptions, Db, DbEntry, DbOptions | browser: main thread (in-memory) or Dedicated Worker (OPFS); Node.js (in-memory) |

newBrowserSqliteDb({ path?, wasmUrl?, capacity? }) returns Promise<Db>. Without path the database is in memory; that also works under Node.js (where a wasmUrl, if given, is a file path). With path it lives in OPFS through the opfs-sahpool VFS, which works only in a Dedicated Worker. capacity raises the number of files that VFS can hold (see below). Use ? placeholders. Bundlers must not pre-bundle @sqlite.org/sqlite-wasm (Vite: optimizeDeps.exclude), or pass wasmUrl.

Examples

// worker.ts — started with new Worker(new URL("./worker.ts", import.meta.url), { type: "module" })
import { newBrowserSqliteDb } from "@statewalker/db-sqlite-browser";

const db = await newBrowserSqliteDb({ path: "/notes.db" });
await db.exec("CREATE VIRTUAL TABLE IF NOT EXISTS notes USING fts5(body)");
const hits = await db.query("SELECT rowid FROM notes WHERE notes MATCH ?", ["sqlite"]);
// A worker that keeps one database per project: reserve room before the default 6 files run out.
const projectId = "p1";
const db = await newBrowserSqliteDb({ path: `/projects/${projectId}.db`, capacity: 64 });

How many databases fit: the pool holds a fixed number of files

opfs-sahpool keeps a pool of OPFS files open for as long as the worker lives, and every file SQLite creates takes one: each database file, whether open or closed, and its rollback journal while a write transaction runs. The pool starts with 6 files, so a worker can keep about five databases if their writes do not overlap.

  • What a full pool looks like. Creating a database, or the journal of its next write, fails with SQLITE_CANTOPEN: sqlite3 result code 14: unable to open database file. It looks like a bad path or a locking problem, but it is the pool running out of files. Opening a database that already exists needs no new file.
  • capacity reserves room. It is the minimum number of files in the pool. It is stored in OPFS with the pool, never shrinks, and costs one open file handle per slot from the moment the worker starts, used or not, which is why the default is small. Size it at about two files per database (the database and its journal), plus a few spare; tens are cheap, hundreds slow the start.
  • Closing a database does not free its file. The data stays in the pool until the file is deleted, and this driver does not delete files.
  • One pool per worker. All databases a worker opens share the pool, and capacity applies to that pool. Each call that passes capacity grows it if needed.

Internals

  • Why OPFS only in a Dedicated Worker. opfs-sahpool uses synchronous OPFS access handles, which browsers provide only in workers. It needs no SharedArrayBuffer, so no COOP/COEP headers. Outside a Dedicated Worker (the main thread, Node.js) a path rejects at once with newBrowserSqliteDb: { path } needs a Dedicated Worker ... rather than falling back to memory.
  • One worker owns a database. The pool holds its OPFS files open while the worker lives; a second worker (or tab) opening the same path fails with an OPFS lock error until the first one is terminated.
  • Calls are queued and transactions open with BEGIN IMMEDIATE (see @statewalker/db-sqlite). Rows are plain objects; BLOBs are Uint8Array; an integer above 2^53 is a bigint, smaller ones are numbers.
  • query runs one statement. SQL with a second statement, or empty SQL, rejects before the engine runs it; true/false, undefined and Date parameters bind as 1/0, NULL and ISO 8601 text. This comes from @statewalker/db-sqlite, the same on every SQLite driver. Use exec for scripts.
  • The engine loads once per wasmUrl. A failed load (a wrong wasmUrl, a network error) is not cached: the next call tries again. The same holds for the OPFS pool: after an open failed with the OPFS lock error, a later open in the same worker works once the other worker is gone.
  • Dependencies: @sqlite.org/sqlite-wasm (the engine), @statewalker/db-sqlite (queue and transactions), @statewalker/db-api (types).

License

MIT