Files
skills/plugins/document-navigator/docs/persistence/database/db-sqlite/README.md
2026-06-09 21:06:27 +01:00

15 KiB

@suaveplan/db-sqlite - Universal SQLite adapter for Suaveplan: bun:sqlite on the Bun server, @sqlite.org/sqlite-wasm in the browser, unified behind a Drizzle-ORM surface with LRU prepared-statement cache, forward-only migration runner, OTel instrumentation, and structured SQLITE.* error codes.

Summary

Universal SQLite adapter for Suaveplan. Runs on bun:sqlite on the Bun server and @sqlite.org/sqlite-wasm (Web Worker) in the browser, unified behind a single SqliteAdapter that implements DatabaseAdapter from @suaveplan/db. Includes an LRU prepared-statement cache (128 entries by default), a forward-only ledger-tracked MigrationRunner with dry-run support, OpenTelemetry span instrumentation, structured SQLITE_* error codes, and a ./unsafe subpath for raw queries.

Documentation tree

  • adapter — (no submodules) - adapter.wasm — Browser-runtime entry point for the……
    • adapter.bun — Bun-runtime entry point for the ./adapter conditional export in @suaveplan/db-sqlite. When a bundler or the Bun run…
    • adapter — (no submodules) - adapter.wasm — Browser-runtime entry point for the……
    • adapter.wasm — Browser-runtime entry point for the ./adapter conditional export in @suaveplan/db-sqlite. When a browser bundler re…
  • cache — (no submodules)
    • cache — (no submodules)
  • conformance — (no submodules)
  • connection — (no submodules)
  • bun-driver — Provides createBunDriver, the server-side SQLite driver for @suaveplan/db-sqlite. It dynamically imports `bun:sqlit…
  • wasm-driver — Provides createWasmDriver, the browser-side SQLite driver for @suaveplan/db-sqlite. It spawns a Web Worker running…
  • wasm-worker — Web Worker implementation for the WASM SQLite driver. This module runs inside a dedicated worker thread created by `cre…
  • errors — (no submodules)
  • migration — (no submodules)
  • otel — (no submodules)
    • otel — (no submodules)
  • schemas — (no submodules)
  • unsafe — (no submodules)
- adapter.wasm — Browser-runtime entry point for the……
  • adapter.bun — Bun-runtime entry point for the ./adapter conditional export in @suaveplan/db-sqlite. When a bundler or the Bun run…

  • adapter — (no submodules)- adapter.wasm — Browser-runtime entry point for the……

  • adapter.wasm — Browser-runtime entry point for the ./adapter conditional export in @suaveplan/db-sqlite. When a browser bundler re…

  • cache — (no submodules)- cache — (no submodules)- conformance — (no submodules)- conformance-suite — (no submodules)- connection — (no submodules)- connection — (no submodules)- bun-driver — Provides createBunDriver, the server-side SQLite driver for @suaveplan/db-sqlite. It dynamically imports `bun:sqlit…

  • wasm-driver — Provides createWasmDriver, the browser-side SQLite driver for @suaveplan/db-sqlite. It spawns a Web Worker running…

  • wasm-worker — Web Worker implementation for the WASM SQLite driver. This module runs inside a dedicated worker thread created by `cre…

  • errors — (no submodules)- errors — (no submodules)- migration — (no submodules)- migration — (no submodules)- otel — (no submodules)- otel — (no submodules)- schemas — (no submodules)- schemas — (no submodules)- unsafe — (no submodules)- unsafe — (no submodules)- adapter.wasm — Browser-runtime entry point for the……

  • adapter.bun — Bun-runtime entry point for the ./adapter conditional export in @suaveplan/db-sqlite. When a bundler or the Bun run…

  • adapter — (no submodules)- adapter.wasm — Browser-runtime entry point for the……

  • adapter.wasm — Browser-runtime entry point for the ./adapter conditional export in @suaveplan/db-sqlite. When a browser bundler re…

  • cache — (no submodules)- cache — (no submodules)- conformance — (no submodules)- conformance-suite — (no submodules)- connection — (no submodules)- connection — (no submodules)- bun-driver — Provides createBunDriver, the server-side SQLite driver for @suaveplan/db-sqlite. It dynamically imports `bun:sqlit…

  • wasm-driver — Provides createWasmDriver, the browser-side SQLite driver for @suaveplan/db-sqlite. It spawns a Web Worker running…

  • wasm-worker — Web Worker implementation for the WASM SQLite driver. This module runs inside a dedicated worker thread created by `cre…

  • errors — (no submodules)- errors — (no submodules)- migration — (no submodules)- migration — (no submodules)- otel — (no submodules)- otel — (no submodules)- schemas — (no submodules)- schemas — (no submodules)- unsafe — (no submodules)- unsafe — (no submodules)- adapter.wasm — Browser-runtime entry point for the…

  • adapter.bun — Bun-runtime entry point for the ./adapter conditional export in @suaveplan/db-sqlite. When a bundler or the Bun run…

  • adapter — (no submodules)- adapter.wasm — Browser-runtime entry point for the…

  • adapter.wasm — Browser-runtime entry point for the ./adapter conditional export in @suaveplan/db-sqlite. When a browser bundler re…

  • cache — (no submodules)- cache — (no submodules)- conformance — (no submodules)- conformance-suite — (no submodules)- connection — (no submodules)- connection — (no submodules)- bun-driver — Provides createBunDriver, the server-side SQLite driver for @suaveplan/db-sqlite. It dynamically imports `bun:sqlit…

  • wasm-driver — Provides createWasmDriver, the browser-side SQLite driver for @suaveplan/db-sqlite. It spawns a Web Worker running…

  • wasm-worker — Web Worker implementation for the WASM SQLite driver. This module runs inside a dedicated worker thread created by `cre…

  • errors — (no submodules)- errors — (no submodules)- migration — (no submodules)- migration — (no submodules)- otel — (no submodules)- otel — (no submodules)- schemas — (no submodules)- schemas — (no submodules)- unsafe — (no submodules)- unsafe — (no submodules)- adapter.bun — Bun-runtime entry point for the ./adapter conditional export in @suaveplan/db-sqlite. When a bundler or the Bun run…

  • adapter — (no submodules)- adapter.wasm — Browser-runtime entry point for the ./adapter conditional export in @suaveplan/db-sqlite. When a browser bundler re…

  • cache — (no submodules) - cache — (no submodules)- conformance — (no submodules) - conformance-suite — (no submodules)- connection — (no submodules) - connection — (no submodules)- bun-driver — Provides createBunDriver, the server-side SQLite driver for @suaveplan/db-sqlite. It dynamically imports `bun:sqlit…

  • wasm-driver — Provides createWasmDriver, the browser-side SQLite driver for @suaveplan/db-sqlite. It spawns a Web Worker running…

  • wasm-worker — Web Worker implementation for the WASM SQLite driver. This module runs inside a dedicated worker thread created by `cre…

  • errors — (no submodules) - errors — (no submodules)- migration — (no submodules) - migration — (no submodules)- otel — (no submodules) - otel — (no submodules)- schemas — (no submodules) - schemas — (no submodules)- unsafe — (no submodules) - unsafe — (no submodules)

Install

bun add @suaveplan/db-sqlite

Quick start

import { createSqliteAdapter } from "@suaveplan/db-sqlite/adapter";

const db = await createSqliteAdapter({ url: ":memory:" });

await db.exec(`
    CREATE TABLE users (
        id TEXT PRIMARY KEY,
        email TEXT NOT NULL
    );
`);

await db.run("INSERT INTO users (id, email) VALUES (?, ?)", [
    "user-123",
    "alice@example.com",
]);

const rows = await db.all<{ id: string; email: string }>(
    "SELECT id, email FROM users WHERE id = ?",
    ["user-123"],
);

await db.close();

Modules

  • Adapter (universal) — SqliteAdapter, createSqliteAdapter, runtime selection
  • Adapter (Bun) — bun:sqlite driver binding
  • Adapter (WASM) — browser/Worker @sqlite.org/sqlite-wasm binding
  • Cache — PreparedStatementCache (LRU)
  • Connection — connection helpers and singleton management
  • Bun driver — low-level Bun SQLite driver
  • WASM driver — low-level WASM SQLite driver
  • WASM worker — Web Worker host for WASM driver
  • Errors — SqliteError, SQLITE_* codes
  • Migration — MigrationRunner, forward-only migration ledger
  • OTel — span and metric instrumentation
  • Schemas — Zod-validated config types
  • Conformance — shared DatabaseAdapter conformance suite
  • Unsafe — ./unsafe subpath for raw queries