Enhanced PrismaClient Types
When you call the enhance
API, ZenStack not only enhances PrismaClient
's runtime behavior, but also alters its types as needed. For example, when you use polymorphic models, ZenStack translates the inheritance hierarchy into a proper Prisma schema following the Multi-table inheritance pattern, however it keeps the typing of the enhanced PrismaClient
simple and provides a real "polymorphic" DX.
You usually don't need to explicitly refer to the enhanced PrismaClient
types, but when you need, import it from the @zenstackhq/runtime/models
module instead of @prisma/client
.
import type { Post, Prisma } from '@zenstackhq/runtime/models'
import { getEnhancedPrisma } from '~/db'
const db = getEnhancedPrisma();
// explicitly refer to the enhanced model type
const post: Post = await db.post.findUnique({...});
// explicitly refer to the enhanced input type
const createInput: Prisma.PostCreateInput = { ... };
await db.post.create({ data: createInput });