You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/200-orm/100-prisma-schema/10-overview/03-generators.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -289,7 +289,7 @@ The following is a list of community created generators.
289
289
-[`prisma-dbml-generator`](https://notiz.dev/blog/prisma-dbml-generator/): Transforms the Prisma schema into [Database Markup Language](https://dbml.dbdiagram.io/home/) (DBML) which allows for an easy visual representation
290
290
-[`prisma-docs-generator`](https://github.com/pantharshit00/prisma-docs-generator): Generates an individual API reference for Prisma Client
291
291
-[`prisma-json-schema-generator`](https://github.com/valentinpalkovic/prisma-json-schema-generator): Transforms the Prisma schema in [JSON schema](https://json-schema.org/)
292
-
-[`prisma-json-types-generator`](https://github.com/arthurfiorette/prisma-json-types-generator): Adds support for [Strongly Typed `Json`](https://github.com/arthurfiorette/prisma-json-types-generator#readme) fields for all databases. It goes on `prisma-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.
292
+
-[`prisma-json-types-generator`](https://github.com/arthurfiorette/prisma-json-types-generator): Enhances `prisma-client-js` (or `prisma-client`) to provide strongly typed JSON fields for all databases, based on your schema. It improves code generation, Intellisense, and more, without affecting runtime code.
293
293
-[`typegraphql-prisma`](https://github.com/MichalLytek/typegraphql-prisma#readme): Generates [TypeGraphQL](https://typegraphql.com/) CRUD resolvers for Prisma models
294
294
-[`typegraphql-prisma-nestjs`](https://github.com/EndyKaufman/typegraphql-prisma-nestjs#readme): Fork of [`typegraphql-prisma`](https://github.com/MichalLytek/typegraphql-prisma), which also generates CRUD resolvers for Prisma models but for NestJS
295
295
-[`prisma-typegraphql-types-gen`](https://github.com/YassinEldeeb/prisma-tgql-types-gen): Generates [TypeGraphQL](https://typegraphql.com/) 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.
Copy file name to clipboardExpand all lines: content/200-orm/200-prisma-client/200-special-fields-and-types/100-working-with-json-fields.mdx
+53-27Lines changed: 53 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -976,46 +976,72 @@ These _null enums_ do not apply to MongoDB because MongoDB does not differentiat
976
976
977
977
</Admonition>
978
978
979
-
## Typed `Json`
979
+
## Typed `Json` Fields
980
980
981
-
By default, `Json` fields are not typed in Prisma models. To accomplish strong typing inside of these fields, you will need to use an external package like [prisma-json-types-generator](https://www.npmjs.com/package/prisma-json-types-generator) to accomplish this.
981
+
Prisma's `Json` fields are untyped by default. To add strong typing, you can use the external package [prisma-json-types-generator](https://www.npmjs.com/package/prisma-json-types-generator).
982
982
983
-
### Using `prisma-json-types-generator`
983
+
1. First, install the package and add the generator to your `schema.prisma`:
984
984
985
-
First, install and configure `prisma-json-types-generator`[according to the package's instructions](https://www.npmjs.com/package/prisma-json-types-generator#using-it).
985
+
```bash
986
+
npm install -D prisma-json-types-generator
987
+
```
986
988
987
-
Then, assuming you have a model like the following:
989
+
```prisma file=schema.prisma
990
+
generator client {
991
+
provider = "prisma-client-js"
992
+
}
988
993
989
-
```prisma no-copy
990
-
model Log {
991
-
id Int @id
992
-
meta Json
993
-
}
994
-
```
994
+
generator json {
995
+
provider = "prisma-json-types-generator"
996
+
}
997
+
```
995
998
996
-
You can update it and type it by using [abstract syntax tree comments](/orm/prisma-schema/overview#comments)
999
+
2. Next, link a field to a TypeScript type using an [AST comment](/orm/prisma-schema/overview#comments).
Now, `Log.meta` will be strongly typed as `{ timestamp: number; host: string }`.
1025
+
1026
+
### Typing `String` Fields and Advanced Features
1027
+
1028
+
You can also apply these techniques to `String` fields. This is especially useful for creating string-based enums directly in your schema when your database does not support enum types.
1029
+
1030
+
```prisma
1031
+
model Post {
1032
+
id Int @id
1033
+
1034
+
/// !['draft' | 'published']
1035
+
status String
1036
+
1037
+
/// [LogMetaType]
1038
+
meta Json[]
1015
1039
}
1016
1040
```
1017
1041
1018
-
Now, when working with `Log.meta` it will be strongly typed!
1042
+
This results in `post.status` being strongly typed as `'draft' | 'published'` and `post.meta` as `LogMetaType[]`.
1043
+
1044
+
For a complete guide on configuration, monorepo setup, and other advanced features, please refer to the [official `prisma-json-types-generator` documentation](https://github.com/arthurfiorette/prisma-json-types-generator#readme).
0 commit comments