{"library":"prisma-json-types-generator","title":"Prisma JSON Types Generator","description":"The `prisma-json-types-generator` is a development-time tool that enhances the Prisma client by providing strict TypeScript typings for `Json` and `String` fields, replacing Prisma's default `JsonValue` with custom, user-defined interfaces. The current stable version is `4.1.1`, which primarily supports Prisma 7 and above, with earlier `v3.x` releases supporting Prisma 6. This package operates during the `prisma generate` step, ensuring all type transformations occur at compile-time without introducing any runtime overhead. Its release cadence generally follows major Prisma version updates, with patch releases for bug fixes and minor improvements. Key differentiators include robust type-safety for complex JSON structures, the ability to define string literal enums without relying on native database enums, flexible type configuration through global namespaces or inline annotations, and compatibility with multiple Prisma clients in a single project. It works seamlessly across all database drivers supported by Prisma.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install prisma-json-types-generator"],"cli":null},"imports":[],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"/* schema.prisma */\ngenerator client {\n  provider = \"prisma-client-js\"\n}\n\ngenerator json {\n  provider  = \"prisma-json-types-generator\"\n  namespace = \"PrismaJson\" // Optional: define a custom namespace for generated types\n  allowAny  = false\n}\n\nmodel User {\n  id        String @id @default(uuid())\n  settings  Json   @db.Text @PrismaJson.UserSettings // Apply custom type\n}\n\n/// @PrismaJson.UserSettings\ntype UserSettings = {\n  theme: \"dark\" | \"light\";\n  notifications: boolean;\n  preferences?: { locale: string; timezone: string; };\n}\n\n/* index.ts */\nimport { PrismaClient } from '@prisma/client';\nimport { UserSettings } from './@prisma/client'; // Import generated type (adjust path as needed if namespace is used)\n\nconst prisma = new PrismaClient();\n\nasync function main() {\n  // Example: Create a user with strongly typed JSON settings\n  const user = await prisma.user.create({\n    data: {\n      settings: {\n        theme: 'dark',\n        notifications: true,\n        preferences: { locale: 'en-US', timezone: 'UTC' }\n      },\n    },\n  });\n\n  console.log('Created user:', user);\n  // Accessing settings provides full TypeScript autocompletion and type-checking\n  console.log('User theme:', user.settings.theme); // 'dark'\n\n  // Example: Update user settings with type-safety\n  const updatedUser = await prisma.user.update({\n    where: { id: user.id },\n    data: {\n      settings: {\n        theme: 'light', // Autocompletion for 'dark' | 'light'\n        notifications: false,\n        preferences: { locale: 'es-ES', timezone: 'America/Mexico_City' }\n      },\n    },\n  });\n\n  console.log('Updated user:', updatedUser);\n  // If you try to assign an invalid type, TypeScript will catch it at compile time.\n  // e.g., updatedUser.settings.theme = 'invalid'; // Type error\n\n}\n\nmain().catch(console.error).finally(() => prisma.$disconnect());","lang":"typescript","description":"This quickstart demonstrates how to configure the `prisma-json-types-generator` in `schema.prisma` to apply custom TypeScript types to a `Json` field. It then shows how to interact with the Prisma client, benefiting from compile-time type-safety and autocompletion for the `settings` field.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}