Skip to content

Add wa-sqlite browser backend for SQLite indexer #584

@marcus-pousette

Description

@marcus-pousette

Goal

Add wa-sqlite (SQLite WASM) support so Peerbit can use a SQLite-backed indexer in the browser (ideally persisted via OPFS), without relying solely on @sqlite.org/sqlite-wasm.

Why

We want a browser-capable SQLite backend for indexing (documents/programs) with:

  • good performance vs pure in-memory indices
  • persistence (OPFS when available)
  • better bundler/runtime ergonomics (Vite/etc)
  • a path that works even when SharedArrayBuffer / cross-origin isolation is not available

Today @peerbit/indexer-sqlite3 already has a browser path via @sqlite.org/sqlite-wasm, but it comes with heavier initialization and constraints. Adding wa-sqlite gives us another implementation option and a fallback for environments where sqlite.org's OPFS/SAH pool approach is problematic.

Scope

A. New backend option

Either:

  • add a new package (suggested): @peerbit/indexer-wa-sqlite, or
  • add a selectable engine inside @peerbit/indexer-sqlite3 (e.g. { engine: 'sqlite.org' | 'wa-sqlite' }).

B. Storage/VFS options

  • OPFS VFS (preferred when available)
  • fallback VFS (memory or IDB) when OPFS is unavailable or locked

C. Worker model

  • run SQLite in a Worker (similar to current proxy/worker model) to keep UI responsive
  • expose a minimal proxy that implements @peerbit/indexer-interface

D. Tooling

  • ensure wasm + worker assets work with the site build (Vite) and CI

Deliverables

  • Browser demo/test that creates an index, writes rows, queries, and persists across reload (when OPFS is enabled)
  • Basic perf sanity check vs current wasm backend (optional)

Acceptance criteria

  • peerbit-org can use a SQLite-backed indexer in the browser without crashing and without special runtime assumptions.
  • Indexer can be configured in apps (Document store / Peerbit.create indexer hook) to pick the wa-sqlite backend.
  • Tests cover the basic read/write/query flow in a browser runtime.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions