Registry / database / kysely-gen

kysely-gen

JSON →
library0.14.1jsnpmunverified

Database type generator for Kysely ORM, supporting PostgreSQL, MySQL, SQLite, and MSSQL. Current stable version is 0.14.1 (released March 2025), actively maintained with weekly releases. Key differentiator: it generates TypeScript types directly from live database schemas, including enums, generated columns, and ColumnType distinctions. Supports Zod schema generation (v4+), camelCase conversion, and pattern-based table filtering. Requires Node >=20 or Bun >=1.

npm install kysely-gen
INSTALL
IMPORT
SIG · KYSELY-GEN
K
kysely-gen
databasejavascriptv0.14.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.

DB
import type { DB } from './db.d.ts'
import { DB } from 'kysely-gen'
Generated types are placed in a local file (default ./db.d.ts). Import from your output file, not from the package.
Generated<T>
import type { Generated } from './db.d.ts'
import { Generated } from 'kysely'
kysely-gen re-exports Generated type with overridden INSERT type. Only import from the generated file.
ColumnType
import type { ColumnType } from './db.d.ts'
import type { ColumnType } from 'kysely'
Same as above — kysely-gen's ColumnType may differ from Kysely's; always import from generated file.
userSchema
import { userSchema } from './db-schemas.ts'
import { userSchema } from 'kysely-gen'
Zod schemas are generated to db-schemas.ts when --zod flag is used. Import from that file.

Illustrates installation, type generation from a PostgreSQL database, and usage of the generated types with a Kysely query.

// 1. Install dependencies // npm install kysely-gen kysely pg // 2. Generate types from PostgreSQL database // DATABASE_URL=postgres://user:pass@localhost:5432/mydb npx kysely-gen --out ./src/db.d.ts --camel-case // 3. Use generated types in your Kysely query import Kysely from 'kysely'; import type { DB } from './src/db.d.ts'; const db = new Kysely<DB>({ dialect: new PostgresDialect({ connectionString: 'postgres://user:pass@localhost:5432/mydb' }) }); const users = await db.selectFrom('users').selectAll().execute(); // users is typed as User[] (from generated DB interface) console.log(users);
Debug
Known issues
breakingZod generation requires Zod v4+. Using Zod v3 or earlier will cause runtime errors.
fix
Upgrade to zod@4 or remove the --zod flag if using older Zod versions.
affects: >=0.12.0
breakingNode.js >=20.0.0 or Bun >=1.0.0 required. Older versions will not work.
fix
Upgrade Node.js to 20+ or switch to Bun 1+.
affects: >=0.14.0
deprecatedThe --schema option is repeatable but deprecated; use --include-pattern for finer control.
fix
Replace --schema with --include-pattern for table filtering.
affects: >=0.13.0
gotchaGenerated types are placed in a local file (db.d.ts) — do not import types from 'kysely-gen' package.
fix
Import types from your generated output file, e.g., import type { DB } from './db.d.ts'.
affects: >=0.1.0
gotchaThe Generated<T> and ColumnType types from kysely-gen may override Kysely's defaults. Always import from the generated file.
fix
Import Generated and ColumnType from your local db.d.ts, not from 'kysely'.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Cannot find module 'kysely-gen'
Running npx kysely-gen without installing the package.
fix
Run `npm install kysely-gen kysely <driver>` first, then use `npx kysely-gen`.
Error: Connection refused. Is your database running?
Database URL is unreachable or credentials are wrong.
fix
Check DATABASE_URL or --url parameter. Ensure database is accessible from your network.
Error: No database driver installed
Missing required peer dependency (pg, mysql2, better-sqlite3, tedious/tarn).
fix
Install the appropriate driver: `npm install pg` for PostgreSQL, etc.
Error: Zod v4+ is required
Using --zod flag with an older version of Zod.
fix
Install zod@4: `npm install zod@4`.
Upgrade
Version history
0.14.1latest on npm
Audit
Dependencies
kyselyrequiredCore dependency for type generation targeting Kysely >=0.27
pgoptionalPostgreSQL client driver
mysql2optionalMySQL client driver
better-sqlite3optionalSQLite client driver
tediousoptionalMSSQL client driver
tarnoptionalMSSQL connection pooling
zodoptionalZod schema generation (v4+ required)
Agent activity
4 hits · last 30 days
node
4
Resources
kysely-gen — npm install kysely-gen · libregistry