Registry / database / kysely-wasqlite-worker

kysely-wasqlite-worker

JSON →
library1.2.1jsnpmunverified

Kysely dialect for wa-sqlite that runs SQL in a Web Worker and stores data in OPFS (Origin Private File System) or IndexedDB. Version 1.2.1 is the latest stable. Released alongside kysely-sqlite-tools monorepo. Key differentiators: no need for custom response headers (unlike official wasm dialect), supports caching/memoization, and provides built-in worker and wasm URL helpers. Requires peer dependencies @subframe7536/sqlite-wasm >=0.5.0 and kysely >=0.26. Fully typed with TypeScript declarations.

npm install kysely-wasqlite-worker
INSTALL
IMPORT
SIG · KYSELY-WASQLITE-WO
K
kysely-wasqlite-worker
databasejavascriptv1.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WaSqliteWorkerDialect
import { WaSqliteWorkerDialect } from 'kysely-wasqlite-worker'
const WaSqliteWorkerDialect = require('kysely-wasqlite-worker')
ESM-only; commonjs require will not work.
createOnMessageCallback
import { createOnMessageCallback } from 'kysely-wasqlite-worker'
import createOnMessageCallback from 'kysely-wasqlite-worker'
Named export, not default.
useDefaultWorker
import { useDefaultWorker } from 'kysely-wasqlite-worker'
import { useDefaultWorker } from 'kysely-wasqlite-worker/worker-module'
useDefaultWorker is exported from main entry, not a subpath.
defaultCreateDatabaseFn
import { defaultCreateDatabaseFn } from 'kysely-wasqlite-worker'
Available since v1.2.0.
WaSqliteWorkerDialectConfig
import type { WaSqliteWorkerDialectConfig } from 'kysely-wasqlite-worker'
TypeScript type import.

Creates a Kysely instance using WaSqliteWorkerDialect, creates a table, inserts a row, selects all, and destroys the database.

import { WaSqliteWorkerDialect } from 'kysely-wasqlite-worker' import { Kysely, SqliteDialect } from 'kysely' const dialect = new WaSqliteWorkerDialect({ fileName: 'my-db', preferOPFS: true, }) const db = new Kysely<{}>({ dialect }) await db.schema.createTable('users').addColumn('name', 'text').execute() await db.insertInto('users').values({ name: 'Alice' }).execute() const users = await db.selectFrom('users').selectAll().execute() console.log(users) const db.destroy()
Debug
Known issues
deprecatedThe worker entry points 'kysely-wasqlite-worker/worker-module' and 'kysely-wasqlite-worker/worker-classic' are deprecated in favor of using useDefaultWorker helper.
fix
Use useDefaultWorker() or pass a custom Worker to the dialect config.
affects: >=1.0.0
breakingVersion 1.0.0 changed the export format from CommonJS to ESM. Requires bundler or Node 16+ with "type": "module".
fix
Use ESM imports and ensure your project or bundler supports ESM.
affects: >=1.0.0
gotchaWhen using Vite, worker format must be set to 'es' in vite.config.ts to avoid build errors.
fix
Add `worker: { format: 'es' }` to vite.config.
affects: >=1.0.0
gotchaOPFS storage only works in secure contexts (localhost or HTTPS). IndexedDB fallback may have limited support in older browsers.
fix
Ensure your app is served over HTTPS or localhost. Check browser compatibility for Locks API and FileSystemSyncAccessHandle.
affects: >=1.0.0
gotchaThis package does not work in Node.js; it is browser-only due to Web Worker and OPFS requirements.
fix
Use only in a browser environment.
affects: >=1.0.0
Errors
Common errors & fixes
Uncaught TypeError: Failed to construct 'Worker': Script at '...' cannot be accessed from origin 'null'.
Using a file:// URL or missing CORS headers for the worker script.
fix
Serve the app over localhost or HTTPS. For development, use a local server (e.g., Vite dev server).
Error: The operation is insecure. (SecurityError)
OPFS is not available in a non-secure context (e.g., http://, file://).
fix
Switch to HTTPS or localhost.
Cannot find module 'kysely-wasqlite-worker/worker-module'
Importing a subpath that may not exist or using CommonJS require with ESM-only exports.
fix
Use `import { useDefaultWorker } from 'kysely-wasqlite-worker'` instead.
kysely: The 'dialect' option must be a Dialect instance.
Forgot to instantiate WaSqliteWorkerDialect with `new`.
fix
Use `new WaSqliteWorkerDialect({...})`.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
@subframe7536/sqlite-wasmrequiredProvides the underlying wa-sqlite implementation and wasm binary.
kyselyrequiredCore query builder and dialect interface.
Agent activity
5 hits · last 30 days
node
4
Resources
kysely-wasqlite-worker — npm install kysely-wasqlite-worker · libregistry