[go: up one dir, main page]

Skip to content

Latest commit

 

History

History

dialect-sqlite-worker

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

kysely-sqlite-worker

kysely dialect for better-sqlite, execute sql in node:worker_threads

the type is also availiable for better-sqlite3-multiple-ciphers

Install

pnpm add kysely kysely-sqlite-worker better-sqlite3

Usage

import { SqliteWorkerDialect } from 'kysely-sqlite-worker'

const dialect = new SqliteWorkerDialect({
  source: ':memory:',
})

Custom Worker

in worker.ts

import { createOnMessageCallback } from 'kysely-sqlite-worker'

createOnMessageCallback(
  async (db) => {
    db.loadExtension(/* ... */)
  }
)

Config

export type SqliteWorkerDialectConfig = {
  /**
   * db file path or existing buffer
   */
  source: string | Buffer | (() => Promisable<string | Buffer>)
  /**
   * better-sqlite3 initiate option
   */
  option?: Options
  onCreateConnection?: (connection: DatabaseConnection) => Promisable<void>
}

Notice

the worker script is read from join(__dirname, 'worker.js') by default, you can customize the path