kysely dialect for better-sqlite, execute sql in node:worker_threads
the type is also availiable for better-sqlite3-multiple-ciphers
pnpm add kysely kysely-sqlite-worker better-sqlite3
import { SqliteWorkerDialect } from 'kysely-sqlite-worker'
const dialect = new SqliteWorkerDialect({
source: ':memory:',
})
in worker.ts
import { createOnMessageCallback } from 'kysely-sqlite-worker'
createOnMessageCallback(
async (db) => {
db.loadExtension(/* ... */)
}
)
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>
}
the worker script is read from join(__dirname, 'worker.js')
by default, you can customize the path