Registry / database / kysely-codegen-sqlite

kysely-codegen-sqlite

JSON →
library0.2.0jsnpmunverified

kysely-codegen-sqlite v0.2.0 generates Kysely type definitions (.d.ts files) directly from SQLite databases. It supports CLI and configuration file usage, camelCase conversion, custom type imports, and requires Node >=20. Unlike generic codegen tools, it is purpose-built for SQLite and integrates tightly with Kysely and better-sqlite3. The library is ESM-only and ships TypeScript types.

npm install kysely-codegen-sqlite
INSTALL
IMPORT
SIG · KYSELY-CODEGEN-SQL
K
kysely-codegen-sqlite
databasejavascriptv0.2.0
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.

DB
import { DB } from 'kysely-codegen-sqlite'
import DB from 'kysely-codegen-sqlite'
DB is a named export, not default. The lib is ESM-only.
Generated
import { Generated } from 'kysely-codegen-sqlite'
Generated is re-exported from generated .d.ts file; you can also import it from 'kysely' directly.
Company
import { Company } from './path/to/generated-file'
import { Company } from 'kysely-codegen-sqlite'
Table interfaces like Company are generated in the output file, not from the package itself.

Shows end-to-end setup: install deps, configure env, run codegen CLI, and use generated DB type with Kysely.

// 1. Install dependencies // npm install --save-dev kysely-codegen-sqlite // npm install kysely better-sqlite3 // 2. Create .env with DATABASE_URL=./path/to/database.db // 3. Run CLI (or add to package.json scripts) // npx kysely-codegen-sqlite --out-file ./src/db/db.d.ts // 4. Use generated types import { Kysely } from 'kysely'; import BetterSqlite3 from 'better-sqlite3'; import { BetterSqlite3Dialect } from 'kysely'; import { DB } from './src/db/db.d.ts'; // path to generated file const db = new Kysely<DB>({ dialect: new BetterSqlite3Dialect({ database: new BetterSqlite3('./database.db'), }), }); const rows = await db.selectFrom('users').selectAll().execute(); // rows is typed as { id: number; name: string; ... }[]
Debug
Known issues
deprecatedNode.js <20 is not supported, but this constraint may change in future versions.
fix
Upgrade Node.js to >=20.0.0 if using this version.
affects: 0.2.0
gotchaGenerated file is overwritten each run; manual changes will be lost.
fix
Do not edit the generated .d.ts file; custom types should be declared separately.
affects: >=0.1.0
gotchaThe DB type export is from the generated file, not from 'kysely-codegen-sqlite' package.
fix
Import DB from the generated output file (e.g., ./db.d.ts) rather than the package name.
affects: >=0.1.0
gotchaCamelCase plugin usage requires --camel-case flag; otherwise column names stay snake_case.
fix
Use CLI argument --camel-case or enable in config file to match Kysely's CamelCasePlugin.
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'kysely-codegen-sqlite' or its corresponding type declarations.
The package is a CLI tool; its types are not used directly in code.
fix
Do not import from 'kysely-codegen-sqlite' in your runtime code. Instead, import the generated .d.ts file.
kysely-codegen-sqlite: command not found
Package not installed globally or node_modules/.bin not in PATH.
fix
Use npx kysely-codegen-sqlite instead of the bare command, or install locally with npm install --save-dev.
Type 'DB' does not satisfy the constraint 'Record<string, KyselyTableDefinition>'.
Generated DB type may be empty if no tables exist or codegen failed.
fix
Ensure your database file is accessible and tables exist. Check DATABASE_URL in .env or provide --db-url explicitly.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
kyselyrequiredPeer dependency; required to use generated types with Kysely ORM
better-sqlite3requiredPeer dependency; used to connect to SQLite database during codegen
Agent activity
8 hits · last 30 days
node
6
Resources
kysely-codegen-sqlite — npm install kysely-codegen-sqlite · libregistry