@subframe7536/sqlite-wasm
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

sqlite-wasm

typesafe wa-sqlite wrapper, run in memory or persist data to IndexedDB or OPFS

low-level layer for kysely-wasqlite-worker-dialect

Usage

Memory

use MemoryVFS with wa-sqlite.wasm, no data persistence

import { getSyncWasmURL, initSQLite, isOpfsSupported, useMemoryStorage } from '@subframe7536/sqlite-wasm'

// optional url
const url = 'https://cdn.jsdelivr.net/gh/rhashimoto/wa-sqlite@v0.9.9/dist/wa-sqlite.wasm'

const { run, changes, lastInsertRowId, close } = await initSQLite(
  useMemoryStorage({ url })
)

IndexedDB

use IDBBatchAtomicVFS with wa-sqlite-async.wasm, larger than sync version, better compatibility

minimal IndexedDB backend browser version

import { useIdbStorage } from '@subframe7536/sqlite-wasm/idb'
import { getAsyncWasmURL, initSQLite } from '@subframe7536/sqlite-wasm'

// optional url
const url = 'https://cdn.jsdelivr.net/gh/rhashimoto/wa-sqlite@v0.9.9/dist/wa-sqlite-async.wasm'

const { run, changes, lastInsertRowId, close } = await initSQLite(
  useIdbStorage('IndexedDB', { url })
)

OPFS

use AccessHandlePoolVFS with wa-sqlite.wasm, smaller than async version

minimal OPFS backend browser version

MUST RUN IN WEB WORKER

import { getSyncWasmURL, initSQLite, isOpfsSupported } from '@subframe7536/sqlite-wasm'
import { useOpfsStorage } from '@subframe7536/sqlite-wasm/opfs'

// optional url
const url = 'https://cdn.jsdelivr.net/gh/rhashimoto/wa-sqlite@v0.9.9/dist/wa-sqlite.wasm'

onmessage = async () => {
  if (!await isOpfsSupported()) { // this can be called in main thread
    return
  }
  const { run, changes, lastInsertRowId, close } = await initSQLite(
    useOpfsStorage('OPFS', url)
  )
}

Package Sidebar

Install

npm i @subframe7536/sqlite-wasm

Weekly Downloads

2

Version

0.2.2

License

MIT

Unpacked Size

2.41 MB

Total Files

21

Last publish

Collaborators

  • subframe7536