Registry / database / kysely-generic-sqlite

kysely-generic-sqlite

JSON →
library1.2.1jsnpmunverified

Generic Kysely dialect for SQLite that supports execution in both main thread and Node.js worker threads. Version 1.2.1, released regularly on npm. Key differentiators: abstraction over SQLite drivers so you can use any SQLite client (better-sqlite3, bun:sqlite, etc.) by providing an executor function. Includes built-in GenericSqliteDialect for main thread and GenericSqliteWorkerDialect for worker threads, with utilities to build query functions and parse big integers. Requires Kysely >=0.26.

npm install kysely-generic-sqlite
INSTALL
IMPORT
SIG · KYSELY-GENERIC-SQL
K
kysely-generic-sqlite
databasejavascriptv1.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GenericSqliteDialect
import { GenericSqliteDialect } from 'kysely-generic-sqlite'
const GenericSqliteDialect = require('kysely-generic-sqlite').GenericSqliteDialect
ESM-only. Default export is not provided.
GenericSqliteWorkerDialect
import { GenericSqliteWorkerDialect } from 'kysely-generic-sqlite/worker'
import { GenericSqliteWorkerDialect } from 'kysely-generic-sqlite'
Worker dialect is in a subpath export 'kysely-generic-sqlite/worker'. Importing from main package will not include it.
createNodeWorkerExecutor
import { createNodeWorkerExecutor } from 'kysely-generic-sqlite/worker-helper-node'
import { createNodeWorkerExecutor } from 'kysely-generic-sqlite'
Helper for Node.js worker threads is in subpath 'kysely-generic-sqlite/worker-helper-node'. There is also a non-Node platform helper at 'kysely-generic-sqlite/worker-helper'.
IGenericSqlite
import type { IGenericSqlite } from 'kysely-generic-sqlite'
TypeScript type; only import as type. Do not use at runtime.
parseBigInt
import { parseBigInt } from 'kysely-generic-sqlite'
const parseBigInt = require('kysely-generic-sqlite').parseBigInt
Utility function to parse large integers from SQLite results (number or BigInt).

Initialize a Kysely instance with a SQLite in-memory database using better-sqlite3 and the GenericSqliteDialect.

import Kysely from 'kysely' import { GenericSqliteDialect } from 'kysely-generic-sqlite' import Database from 'better-sqlite3' import type { IGenericSqlite } from 'kysely-generic-sqlite' const db = new Database(':memory:') const executor: IGenericSqlite<Database> = { db, query: (_isSelect: boolean, sql: string, parameters?: readonly unknown[]) => { const stmt = db.prepare(sql) if (stmt.reader) { return { rows: stmt.all(parameters as any) } } const { changes, lastInsertRowid } = stmt.run(parameters as any) return { rows: [], numAffectedRows: BigInt(changes), insertId: BigInt(lastInsertRowid), } }, close: () => db.close(), iterator: (_isSelect: boolean, sql: string, parameters?: readonly unknown[]) => { return db.prepare(sql).iterate(parameters as any) }, } const dialect = new GenericSqliteDialect(executor) const kysely = new Kysely<any>({ dialect }) await kysely.schema.createTable('test').addColumn('id', 'integer').execute() await kysely.insertInto('test').values({ id: 1 }).execute() const rows = await kysely.selectFrom('test').selectAll().execute() console.log(rows)
Debug
Known issues
breakingThe dialect does not work out-of-box; you must provide an executor function implementing IGenericSqlite. This is not a fully fledged dialect.
fix
Implement IGenericSqlite for your chosen SQLite client (better-sqlite3, bun:sqlite, etc.).
affects: >=0.0
deprecatedThe library is still actively maintained; no deprecations yet.
affects: <2
gotchaWorker dialect imports must come from subpaths: 'kysely-generic-sqlite/worker' and 'kysely-generic-sqlite/worker-helper-node'. Importing from the main package will not include these.
fix
Use the correct subpath import as shown in the documentation.
affects: >=1.0
gotchaThe library is ESM-only. CommonJS require() may not work, or may require dynamic import().
fix
Use ES module import syntax, or configure your project to handle ESM packages.
affects: >=1.0
Errors
Common errors & fixes
Cannot find module 'kysely-generic-sqlite/worker'
Attempting to import from 'kysely-generic-sqlite/worker' without using the correct subpath export; possibly trying to import from main package.
fix
Ensure you are using a modern bundler or Node.js version that supports package.json exports. Import exactly: import { GenericSqliteWorkerDialect } from 'kysely-generic-sqlite/worker'
TypeError: executor.query is not a function
The executor object passed to GenericSqliteDialect does not have a query method or does not conform to IGenericSqlite interface.
fix
Implement the IGenericSqlite interface with a query method that returns an object with 'rows' and optionally 'numAffectedRows' and 'insertId'.
error: Unsupported import path: 'kysely-generic-sqlite' does not export 'GenericSqliteWorkerDialect'
Importing GenericSqliteWorkerDialect from the main package instead of the worker subpath.
fix
Change import to: import { GenericSqliteWorkerDialect } from 'kysely-generic-sqlite/worker'
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
kyselyoptionalPeer dependency; the library provides a Kysely dialect and requires Kysely >=0.26 to function.
Agent activity
6 hits · last 30 days
node
4
Resources
kysely-generic-sqlite — npm install kysely-generic-sqlite · libregistry