diff --git a/docs/reference/enhanced-types.md b/docs/reference/enhanced-types.md new file mode 100644 index 00000000..bfa5470d --- /dev/null +++ b/docs/reference/enhanced-types.md @@ -0,0 +1,25 @@ +--- +description: Enhancements to the types generated by Prisma +sidebar_position: 4 +sidebar_label: Enhanced PrismaClient Types +--- + +# Enhanced PrismaClient Types + +When you call the [`enhance`](./runtime-api#enhance) API, ZenStack not only enhances `PrismaClient`'s runtime behavior, but also alters its types as needed. For example, when you use [polymorphic models](../guides/polymorphism), ZenStack translates the inheritance hierarchy into a proper Prisma schema following the [Multi-table inheritance](https://www.prisma.io/docs/orm/prisma-schema/data-model/table-inheritance#multi-table-inheritance-mti) 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`. + +```ts +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 }); +``` diff --git a/docs/reference/error-handling.md b/docs/reference/error-handling.md index f25da75d..07d31586 100644 --- a/docs/reference/error-handling.md +++ b/docs/reference/error-handling.md @@ -1,6 +1,6 @@ --- description: Error handling -sidebar_position: 7 +sidebar_position: 8 --- # Error Handling diff --git a/docs/reference/plugins/_category_.yml b/docs/reference/plugins/_category_.yml index 29d8f6f3..4a2a7dc0 100644 --- a/docs/reference/plugins/_category_.yml +++ b/docs/reference/plugins/_category_.yml @@ -1,4 +1,4 @@ -position: 5 +position: 6 label: Plugins collapsible: true collapsed: true diff --git a/docs/reference/prisma-client-ext.md b/docs/reference/prisma-client-ext.md index 4cb01b78..39e0d240 100644 --- a/docs/reference/prisma-client-ext.md +++ b/docs/reference/prisma-client-ext.md @@ -1,6 +1,6 @@ --- description: APIs ZenStack adds to the PrismaClient -sidebar_position: 4 +sidebar_position: 5 sidebar_label: Added PrismaClient APIs --- diff --git a/docs/reference/server-adapters/_category_.yml b/docs/reference/server-adapters/_category_.yml index a69eb540..f6e05f3e 100644 --- a/docs/reference/server-adapters/_category_.yml +++ b/docs/reference/server-adapters/_category_.yml @@ -1,4 +1,4 @@ -position: 6 +position: 7 label: Server Adapters collapsible: true collapsed: true