1.1.0 • Published 5 months ago

kysely-sqlite-worker v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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, defaultCreateDatabaseFn } from 'kysely-sqlite-worker'

createOnMessageCallback(
  async (...args) => {
    const db = defaultCreateDatabaseFn(...args)
    db.loadExtension(/* ... */)
    return db
  },
  ([type, exec, data1, data2, data3]) => {
    if (type === 'export') {
      return exec.db.export()
    }
  }
)

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

1.1.0

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago

0.7.0

9 months ago

0.6.3

11 months ago

0.6.2

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.5.7

1 year ago

0.5.6

2 years ago

0.5.4

2 years ago

0.5.3

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.5.0

2 years ago

0.4.5

2 years ago

0.4.4

2 years ago

0.4.7

2 years ago

0.4.6

2 years ago

0.4.0

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago