Skip to content

feat: add OPFSWriteAheadVFS storage wrapper#14

Merged
subframe7536 merged 3 commits intomainfrom
copilot/create-opfs-write-ahead-vfs-wrapper
Apr 19, 2026
Merged

feat: add OPFSWriteAheadVFS storage wrapper#14
subframe7536 merged 3 commits intomainfrom
copilot/create-opfs-write-ahead-vfs-wrapper

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 19, 2026

Adds a new storage backend wrapping OPFSWriteAheadVFS — a synchronous OPFS VFS with WAL2-style journaling that enables concurrent reads, faster writes, and no blocking checkpoints.

Changes

  • src/vfs/opfs-write-ahead.tsuseOpfsWriteAheadStorage(path, options) wrapping OPFSWriteAheadVFS; uses sync wa-sqlite.wasm build; accepts nTmpFiles, autoCheckpoint, backstopInterval
  • src/types/index.tsOPFSWriteAheadVFSOptions interface
  • src/types/wa-sqlite.d.ts — module declaration for wa-sqlite/src/examples/OPFSWriteAheadVFS.js
  • src/utils.ts — new isOpfsReadWriteUnsafeSupported() utility to detect OPFS readwrite-unsafe locking mode support (Chromium only)
  • tsdown.config.ts / package.json — new opfs-wa build entry and ./opfs-wa package export
  • .gitignore — exclude package-lock.json
  • README.md — usage section with caniuse link for minimal browser version, using isOpfsReadWriteUnsafeSupported in example, Chromium-only requirement, Worker constraint, and WAL restrictions

Usage

import { initSQLite, isOpfsReadWriteUnsafeSupported } from '@subframe7536/sqlite-wasm'
import { useOpfsWriteAheadStorage } from '@subframe7536/sqlite-wasm/opfs-wa'

// must run in web worker
if (await isOpfsReadWriteUnsafeSupported()) {
  const { run, changes, lastInsertRowId, close } = await initSQLite(
    useOpfsWriteAheadStorage('test.db'),
  )
}

Restrictions: Chromium only (requires OPFS readwrite-unsafe); must run in a Worker; multi-statement write transactions require BEGIN IMMEDIATE or BEGIN EXCLUSIVE.

Copilot AI and others added 2 commits April 19, 2026 07:35
Copy link
Copy Markdown
Owner

@subframe7536 subframe7536 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exclude package-lock.json; add OPFS readwrite-unsafe support check util, note the minimal version and update relative example in readme

…son, update readme

Agent-Logs-Url: https://github.com/subframe7536/sqlite-wasm/sessions/39e80190-e7fa-4a42-8312-4657d6dda0de

Co-authored-by: subframe7536 <78338239+subframe7536@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 19, 2026

exclude package-lock.json; add OPFS readwrite-unsafe support check util, note the minimal version and update relative example in readme

Done in 3e813ab:

  • package-lock.json added to .gitignore and removed from tracking
  • Added isOpfsReadWriteUnsafeSupported() to src/utils.ts — detects readwrite-unsafe mode support by attempting createSyncAccessHandle({ mode: 'readwrite-unsafe' }) in the current Worker context (must run in worker, same as the VFS itself)
  • README OPFS Write-Ahead section now uses isOpfsReadWriteUnsafeSupported in the example and links to caniuse for minimal browser version

@subframe7536 subframe7536 marked this pull request as ready for review April 19, 2026 09:18
@subframe7536 subframe7536 merged commit 7bed48a into main Apr 19, 2026
@subframe7536 subframe7536 deleted the copilot/create-opfs-write-ahead-vfs-wrapper branch April 19, 2026 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants