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);
}
Errors
Common errors & fixes
Error: Cannot find module 'kysely-generate'
Package not installed or imported incorrectly.
fixInstall 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.
fixCreate 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).
fixInstall 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.
fixVerify 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.
fixCheck DATABASE_URL, network connectivity, and firewall rules. Ensure the database server is running.
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)