Socket
Book a DemoInstallSign in
Socket

kysely-bun-worker

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kysely-bun-worker

kysely dialect for bun:sqlite, running in worker

latest
Source
npmnpm
Version
1.2.1
Version published
Maintainers
1
Created
Source

kysely-bun-worker

kysely dialect for bun:sqlite, run sql in worker

From v0.7.0, this dialect requires Bun@^1.1.14

Install

bun install kysely kysely-bun-worker

Usage

import { BunWorkerDialect } from 'kysely-bun-worker'

const dialect = new BunWorkerDialect({
  // default
  url: ':memory:',
})

Custom Worker

in worker.ts

import { createOnMessageCallback, defaultCreateDatabaseFn } from 'kysely-bun-worker'

createOnMessageCallback(
  async (...args) => {
    const db = defaultCreateDatabaseFn(...args)
    db.loadExtension(/* ... */)
    return db
  }
)

Normal Dialect

In v1.1.0, you can use BunSqliteDialect to run SQLs in main thread

import { BunSqliteDialect } from 'kysely-bun-worker/normal'

const dialect = new BunSqliteDialect({
  // default
  url: ':memory:',
})

Config

export type BunWorkerDialectConfig = {
  /**
   * db file path
   *
   * @default ':memory:'
   */
  url?: string
  onCreateConnection?: (connection: DatabaseConnection) => Promisable<void>
  /**
   * use bun:sqlite's built-in statment cache
   * @see https://bun.sh/docs/api/sqlite#query
   */
  cacheStatment?: boolean
  /**
   * custom worker, default is a worker that use bun:sqlite
   */
  worker?: Worker
  /**
   * DB constructor options
   * @default { create: true }
   */
  dbOptions?: ConstructorParameters<typeof Database>[1]
}

Keywords

kysely

FAQs

Package last updated on 26 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts