prisma-effect-kysely
v5.9.0
Published
Prisma generator that creates Effect Schema types from Prisma schema compatible with Kysely
Maintainers
Readme
prisma-effect-kysely
Prisma generator producing Effect Schema types with Kysely-compatible column metadata, branded IDs, and intelligent UUID detection.
Install
bun add prisma-effect-kyselySetup
generator effect_schemas {
provider = "prisma-effect-kysely"
output = "./generated/effect"
}npx prisma generateOutput
Three files: enums.ts, types.ts, index.ts.
import { Schema } from "effect";
import { columnType, DateFromInput, generated, Selectable } from "prisma-effect-kysely";
// Branded ID
export const UserId = Schema.UUID.pipe(Schema.brand("UserId"));
export type UserId = typeof UserId.Type;
// Model schema
export const User = Schema.Struct({
id: columnType(Schema.UUID, Schema.Never, Schema.Never),
email: Schema.String,
createdAt: generated(DateFromInput),
});
export type User = typeof User;
// Kysely DB interface
export interface DB {
User: Selectable<User>;
}Consumer Usage
import { Selectable, Insertable, Updateable } from "prisma-effect-kysely";
import { User, UserId, DB } from "./generated";
function getUser(id: UserId): Promise<User> { ... }
type UserSelect = Selectable<typeof User>;
type UserInsert = Insertable<typeof User>;
type UserUpdate = Updateable<typeof User>;
const db = new Kysely<DB>({ ... });Schema names are PascalCase regardless of Prisma model name (session_preference → SessionPreference).
Field Behavior
@default/@updatedAt→generated()(omitted from insert, optional in update)@idwith@default→columnType(type, Never, Never)(read-only)- Optional fields →
Schema.NullOr(type) - Foreign keys → branded ID type from target model
Type Mappings
| Prisma | Effect Schema |
| ----------- | --------------------- |
| String | Schema.String |
| Int / Float | Schema.Number |
| BigInt | Schema.BigInt |
| Decimal | Schema.String |
| Boolean | Schema.Boolean |
| DateTime | DateFromInput |
| Json | JsonValue |
| Bytes | Schema.Uint8Array |
| Enum | Schema.Literal(...) |
| UUID | Schema.UUID |
Arrays → Schema.Array(t). Nullable → Schema.NullOr(t). DateFromInput accepts Date | string on the encoded side; JsonValue is Schema<JsonValue, JsonValue>. Both are wire-safe (JSON.parse output decodes cleanly).
UUID Detection
Priority order:
- Native type:
@db.Uuid - Documentation:
@db.Uuidin field comment - Field name pattern:
id,*_id,*_uuid,uuid
Custom Type Overrides
Use @customType in field docs to override Effect Schema:
model User {
/// @customType(Schema.String.pipe(Schema.email()))
email String @unique
/// @customType(Schema.Number.pipe(Schema.positive()))
age Int
}Supported on all Prisma scalar types.
Implicit M2M Join Tables
Prisma columns A/B map to semantic snake_case fields via Schema.fromKey:
export const ProductToProductTag = Schema.Struct({
product_id: Schema.propertySignature(
columnType(Schema.UUID, Schema.Never, Schema.Never)
).pipe(Schema.fromKey("A")),
product_tag_id: Schema.propertySignature(
columnType(Schema.UUID, Schema.Never, Schema.Never)
).pipe(Schema.fromKey("B")),
});Package Exports
| Entry | Contents |
| -------------------------------- | ----------------------------------------------------- |
| prisma-effect-kysely | Type utilities + runtime helpers (default import) |
| prisma-effect-kysely/generator | Prisma generator binary entry |
| prisma-effect-kysely/kysely | getSchemas, columnType, generated, type utils |
| prisma-effect-kysely/error | NotFoundError, QueryError, QueryParseError, ... |
| prisma-effect-kysely/runtime | All runtime utilities |
Development
bun install
bun run test
bun run typecheck
bun run build
bun run prepublishOnly # lint + typecheck + test + buildReleasing
Uses Changesets.
bun changeset # add changeset
git add .changeset/ && git commit -m "docs: changeset"
git pushCI opens a "Version Packages" PR. Merging it publishes to npm, tags, and creates a GitHub release. Requires NPM_TOKEN repo secret.
License
MIT
