Registry / devops / kysely-generate

kysely-generate

JSON →
library0.21.6jsnpmunverified

TypeScript type generator for Kysely ORM that creates database type definitions from introspection. v0.21.6 supports PostgreSQL, MySQL, SQLite, MSSQL, and LibSQL. Active fork adding materialized view introspection, Postgres.js dialect, improved MSSQL auth (NTLM), dateStrings-aware MySQL typing, and ESM/CJS dual build (tsdown). Requires Kysely >=0.27.0. Differentiator: CLI-first with .env and config file support, generates complete DB interface with Generated and Timestamp helpers.

npm install kysely-generate
INSTALL
IMPORT
SIG · KYSELY-GENERATE
K
kysely-generate
devopsjavascriptv0.21.6
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-generate'
import DB from 'kysely-generate'
DB is a named export, not default. The generated file is typically written to a custom path, not imported from kysely-generate package itself.
Generated
import { Generated } from 'kysely-generate'
import { Generated } from 'kysely'
Generated helper type is exported by kysely-generate (and also by Kysely itself). Prefer importing from kysely for consistency.
Timestamp
import { Timestamp } from 'kysely-generate'
import { Timestamp } from 'kysely'
Same as Generated — the type is generated by kysely-generate and exported from the output file, but you can also define your own.

Shows how to generate Kysely type definitions from DATABASE_URL and use them in a Kysely query.

// Ensure .env file is present with DATABASE_URL set // Then run: // npx kysely-generate // Example command to generate types to ./src/db/db.d.ts // npx kysely-generate --out-file ./src/db/db.d.ts // Use generated types in your code: import { Kysely, PostgresDialect } from 'kysely'; import { DB } from './path/to/db'; import { Pool } from 'pg'; const db = new Kysely<DB>({ dialect: new PostgresDialect({ pool: new Pool({ connectionString: process.env.DATABASE_URL ?? '', }), }), }); async function getUsers() { const rows = await db.selectFrom('users').selectAll().execute(); console.log(rows); }
Debug
Known issues
gotchaThe package is a fork of kysely-codegen with additional features; migration may require changes if you used custom codegen plugins.
fix
Review the fork's changes and adjust your schema accordingly.
affects: >=0.0.0
gotchaRequires Node >=20.0.0; older Node versions will fail.
fix
Upgrade Node.js to >=20.0.0.
affects: >=0.21.0
breakingThe Generated type helpers (Generated, Timestamp) are no longer imported from kysely but are exported from the generated .d.ts file. This changes how you reference them in type annotations.
fix
If you previously imported them from kysely, you can continue to do so; the generated file also exports them, but using both may cause conflicts.
affects: >=0.27.0
gotchaMSSQL NTLM auth requires @tediousjs/connection-string@^1.0.0 as a peer dependency; missing it will cause connection string parsing errors.
fix
Install @tediousjs/connection-string: npm install @tediousjs/connection-string@^1.0.0
affects: >=0.21.0
gotchaIf using PlanetScale, you must add ssl={"rejectUnauthorized":true} to your DATABASE_URL query string.
fix
Add ssl={"rejectUnauthorized":true} to your connection URL.
affects: >=0.0.0
gotchaThe output file path (--out-file) must be relative to the current working directory; absolute paths may not work correctly on Windows.
fix
Use relative paths for --out-file.
affects: >=0.21.0
Errors
Common errors & fixes
Error: Cannot find module 'kysely-generate'
Package not installed or imported incorrectly.
fix
Install the package: npm install --save-dev kysely-generate. Then run the CLI, not the JS module.
kysely-generate: error: missing required argument 'DATABASE_URL'
No .env file or DATABASE_URL environment variable set.
fix
Create a .env file with DATABASE_URL or set the environment variable before running the command.
Error: Cannot use 'kysely' as a module without a database driver installed.
Missing required database driver (e.g., pg, mysql2, better-sqlite3).
fix
Install the appropriate driver: e.g., npm install kysely pg
Error: Cannot generate types: no tables found in database
Database connection succeeded but schema is empty or the user lacks permissions.
fix
Verify the database contains tables and the user has SELECT privileges on information_schema.
Error: Connection timeout. Is your database reachable?
Network issue, firewall, or wrong host/port.
fix
Check DATABASE_URL, network connectivity, and firewall rules. Ensure the database server is running.
Upgrade
Version history
0.21.6latest on npm
Audit
Dependencies
kyselyrequiredrequired for generated type definitions to work with Kysely<DB>
pgoptionalPostgreSQL driver (required if using PostgreSQL)
postgresoptionalPostgres.js driver (required if using --dialect=postgres-js)
kysely-postgres-jsoptionalPostgres.js dialect adapter (required if using --dialect=postgres-js)
mysql2optionalMySQL driver (required if using MySQL)
better-sqlite3optionalSQLite driver (required if using SQLite)
tediousoptionalMSSQL driver (required if using MSSQL)
tarnoptionalMSSQL connection pool (required if using MSSQL)
@tediousjs/connection-stringoptionalEnhanced MSSQL connection string parsing with NTLM auth (required if using MSSQL)
@libsql/kysely-libsqloptionalLibSQL dialect adapter (required if using LibSQL)
Agent activity
4 hits · last 30 days
node
4
Resources
kysely-generate — npm install kysely-generate · libregistry