0.6.1 • Published 4 days ago

kysely-wasqlite-worker v0.6.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 days ago

kysely-wasqlite-worker

kysely dialect for wa-sqlite, execute sql in Web Worker, store data in OPFS or IndexedDB

No need to set response header like official wasm

Install

pnpm add kysely kysely-wasqlite-worker

Config

export interface WaSqliteWorkerDialectConfig {
  /**
   * db file name
   */
  fileName: string
  /**
   * prefer to store data in OPFS
   * @default true
   */
  preferOPFS?: boolean
  /**
   * wasqlite worker
   *
   * built-in: {@link useDefaultWorker}
   * @param supportModuleWorker if support { type: 'module' } in worker options
   * @example
   * import { useDefaultWorker } from 'kysely-wasqlite-worker'
   * @example
   * (support) => support
   *   ? new Worker(
   *       new URL('kysely-wasqlite-worker/worker-module', import.meta.url),
   *       { type: 'module', credentials: 'same-origin' }
   *     )
   *   : new Worker(
   *       new URL('kysely-wasqlite-worker/worker-classic', import.meta.url),
   *       { type: 'classic', name: 'test' }
   *     )
   */
  worker: Worker | ((supportModuleWorker: boolean) => Worker)
  /**
   * wasm URL
   *
   * built-in: {@link useDefaultWasmURL}
   * @param useAsyncWasm if need to use wa-sqlite-async.wasm
   * @example
   * import { useDefaultWasmURL } from 'kysely-wasqlite-worker'
   * @example
   * (useAsync) => useAsync
   *   ? 'https://cdn.jsdelivr.net/gh/rhashimoto/wa-sqlite@v0.9.9/dist/wa-sqlite-async.wasm'
   *   : new URL('kysely-wasqlite-worker/wasm-sync', import.meta.url).href
   */
  url: string | ((useAsyncWasm: boolean) => string)
  onCreateConnection?: (connection: DatabaseConnection) => Promisable<void>
}

Usage

import {
  WaSqliteWorkerDialect,
  generateDialectOptions,
  isIdbSupported,
  isModuleWorkerSupport,
  isOpfsSupported,
  useDefaultWasmURL,
  useDefaultWorker
} from 'kysely-wasqlite-worker'

const dialect = new WaSqliteWorkerDialect({
  fileName: 'test',
})

see more in playground

if throw error when using Vite to build, add worker config

export default defineConfig({
  // ...
  worker: {
    format: 'es',
  },
})

Limitation

0.6.1

4 days ago

0.6.0

2 months ago

0.5.7

3 months ago

0.5.6

4 months ago

0.5.4

5 months ago

0.5.3

6 months ago

0.5.2

6 months ago

0.5.1

6 months ago

0.5.0

6 months ago

0.4.5

7 months ago

0.4.4

7 months ago

0.4.7

6 months ago

0.4.6

7 months ago

0.4.0

8 months ago

0.4.3

8 months ago

0.4.2

8 months ago

0.3.8

10 months ago

0.3.7

10 months ago

0.3.6

10 months ago

0.3.5

10 months ago

0.3.4

11 months ago

0.3.3

11 months ago

0.3.2

11 months ago

0.3.1

11 months ago

0.3.0

11 months ago