Generators
A Prisma schema can have one or more generators, represented by the generator
block:
generator client {
provider = "prisma-client-js"
output = "./generated/prisma-client-js"
}
A generator determines which assets are created when you run the prisma generate
command. The main property provider
defines which Prisma Client (language specific) is created - currently, only prisma-client-js
is available. Alternatively you can define any npm package that follows our generator specification. Additionally and optionally you can define a custom output folder for the generated assets with output
.
Prisma Client: prisma-client-js
The generator for Prisma's JavaScript Client accepts multiple additional properties:
previewFeatures
: Preview features to includebinaryTargets
: Engine binary targets forprisma-client-js
(for example,debian-openssl-1.1.x
if you are deploying to Ubuntu 18+, ornative
if you are working locally)
generator client {
provider = "prisma-client-js"
previewFeatures = ["sample-preview-feature"]
binaryTargets = ["linux-musl"]
}
Binary targets
Prisma Client JS (prisma-client-js
) uses several engines. Engines are implemented in Rust and are used by Prisma Client in the form of executable, platform dependent engine files. Depending on which platform you are executing your code on, you need the correct file. "Binary targets" are used to define which files should be present for the target platform(s).
The correct file is particularly important when deploying your application to production, which often differs from your local development environment.
The native
binary target
The native
binary target is special. It doesn't map to a concrete operating system. Instead, when native
is specified in binaryTargets
, Prisma Client detects the current operating system and automatically specifies the correct binary target for it.
As an example, assume you're running macOS and you specify the following generator:
generator client {
provider = "prisma-client-js"
binaryTargets = ["native"]
}
In that case, Prisma Client detects your operating system and finds the right binary file for it based on the list of supported operating systems .
If you use macOS Intel x86 (darwin
), then the binary file that was compiled for darwin
will be selected.
If you use macOS ARM64 (darwin-arm64
), then the binary file that was compiled for darwin-arm64
will be selected.
Note: The
native
binary target is the default. You can set it explicitly if you wish to include additional binary targets for deployment to different environments.
Community generators
Existing generators or new ones should not be affected if you are using the prismaSchemaFolder
preview feature to manage multiple schema files, unless a generator reads the schema manually.
The following is a list of community created generators.
prisma-dbml-generator
: Transforms the Prisma schema into Database Markup Language (DBML) which allows for an easy visual representationprisma-docs-generator
: Generates an individual API reference for Prisma Clientprisma-json-schema-generator
: Transforms the Prisma schema in JSON schemaprisma-json-types-generator
: Adds support for Strongly TypedJson
fields for all databases. It goes onprisma-client-js
output and changes the json fields to match the type you provide. Helping with code generators, intellisense and much more. All of that without affecting any runtime code.typegraphql-prisma
: Generates TypeGraphQL CRUD resolvers for Prisma modelstypegraphql-prisma-nestjs
: Fork oftypegraphql-prisma
, which also generates CRUD resolvers for Prisma models but for NestJSprisma-typegraphql-types-gen
: Generates TypeGraphQL class types and enums from your prisma type definitions, the generated output can be edited without being overwritten by the next gen and has the ability to correct you when you mess up the types with your edits.nexus-prisma
: Allows to project Prisma models to GraphQL via GraphQL Nexusprisma-nestjs-graphql
: Generates object types, inputs, args, etc. from the Prisma Schema for usage with@nestjs/graphql
moduleprisma-appsync
: Generates a full-blown GraphQL API for AWS AppSyncprisma-kysely
: Generates type definitions for Kysely, a TypeScript SQL query builder. This can be useful to perform queries against your database from an edge runtime, or to write more complex SQL queries not possible in Prisma without dropping type safety.prisma-generator-nestjs-dto
: Generates DTO and Entity classes with relationconnect
andcreate
options for use with NestJS Resources and @nestjs/swaggerprisma-erd-generator
: Generates an entity relationship diagramprisma-generator-plantuml-erd
: Generator to generate ER diagrams for PlantUML. Markdown and Asciidoc documents can also be generated by activating the option.prisma-class-generator
: Generates classes from your Prisma Schema that can be used as DTO, Swagger Response, TypeGraphQL and so on.zod-prisma
: Creates Zod schemas from your Prisma models.prisma-pothos-types
: Makes it easier to define Prisma-based object types, and helps solve n+1 queries for relations. It also has integrations for the Relay plugin to make defining nodes and connections easy and efficient.prisma-generator-pothos-codegen
: Auto generate input types (for use as args) and auto generate decoupled type-safe base files makes it easy to create customizable objects, queries and mutations for Pothos from Prisma schema. Optionally generate all crud at once from the base files.prisma-joi-generator
: Generate full Joi schemas from your Prisma schema.prisma-yup-generator
: Generate full Yup schemas from your Prisma schema.prisma-class-validator-generator
: Emit TypeScript models from your Prisma schema with class validator validations ready.prisma-zod-generator
: Emit Zod schemas from your Prisma schema.prisma-trpc-generator
: Emit fully implemented tRPC routers.prisma-json-server-generator
: Emit a JSON file that can be run with json-server.prisma-trpc-shield-generator
: Emit a tRPC shield from your Prisma schema.prisma-custom-models-generator
: Emit custom models from your Prisma schema, based on Prisma recommendations.nestjs-prisma-graphql-crud-gen
: Generate CRUD resolvers from GraphQL schema with NestJS and Prisma.prisma-generator-dart
: Generates Dart/Flutter class files with to- and fromJson methods.prisma-generator-graphql-typedef
: Generates graphql schema.prisma-markdown
: Generates markdown document composed with ERD diagrams and their descriptions. Supports pagination of ERD diagrams through@namespace
comment tag.prisma-models-graph
: Generates a bi-directional models graph for schema without strict relationship defined in the schema, works via a custom schema annotation.prisma-generator-fake-data
: Generates realistic-looking fake data for your Prisma models that can be used in unit/integration tests, demos, and more.prisma-generator-drizzle
: A Prisma generator for generating Drizzle schema with ease.prisma-generator-express
: Generates Express CRUD and Router generator function.prismabox
: Generates versatile typebox schema from your Prisma models.prisma-generator-typescript-interfaces
: Generates zero-dependency TypeScript interfaces from your Prisma schema.