prisma-kysely

A Prisma generator that emits fully typed Kysely database definitions from your Prisma schema.

Tool
npm
v3.2.1
1,183stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
72/100Good
Development Activity72
Maintenance76
Community48
Maturity52
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture78
Code Quality80
Innovation76
Learning Curve85

prisma-kysely is a Prisma generator that lets you keep using Prisma’s schema language and migration workflow while querying your database with Kysely, the type-safe SQL query builder. During prisma generate it reads your schema and emits a set of Kysely-compatible TypeScript types, so your hand-written SQL stays fully typed and in sync with the schema.

It supports multiple SQL dialects, configurable type overrides, enum and JSON handling, and Cloudflare D1, making it a popular bridge for teams that want Prisma’s ergonomics for modeling and migrations but Kysely’s control and performance for queries.

What You Get

  • A prisma-kysely generator block you add to your schema.prisma
  • Generated Kysely Database interface and per-table type definitions
  • Configurable type overrides for columns, enums, and JSON fields
  • Support for multiple SQL dialects including Cloudflare D1
  • A single schema as the source of truth for both migrations and query types

Common Use Cases

  • Using Prisma for schema modeling and migrations while running queries through Kysely
  • Getting fully typed raw-SQL query building without maintaining hand-written types
  • Generating database types for edge runtimes and Cloudflare D1 from a Prisma schema

Under The Hood

Architecture - The generator entry point in src/bin.ts registers with @prisma/generator-helper; src/generator.ts walks the parsed schema (via @mrleebo/prisma-ast and @prisma/internals) and, with helpers under src/helpers and src/utils, maps each model, field, and enum onto a Kysely type, emitting a TypeScript file. Dialect-specific behavior is exercised by src/dialectTests.

Tech Stack - Written in TypeScript and distributed as a CLI binary (dist/bin.js). It depends on @prisma/generator-helper, @prisma/internals, @mrleebo/prisma-ast, typescript, and zod for validating generator configuration.

Code Quality - The codebase includes a __test__ suite plus dedicated dialect test fixtures, uses zod to validate options, and keeps type-mapping logic separated into small helper modules. Naming is descriptive and the transformation pipeline is easy to follow.

API Design - Configuration is declarative: you add a generator block to schema.prisma with a handful of options (output path, dialect, type overrides). There is no imperative API to learn — the tool runs as part of the standard prisma generate flow, so adoption is a few lines of schema config.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search