With the release of version 4.16.0 of the Prisma ORM, Client extensions are now Generally Available! This new feature allows users to extend and customize Prisma Client to meet their individual use cases.
Tailor Prisma Client to meet your codebase's needs
In 4.7.0, we released Prisma Client extensions as a Preview feature. Today we are happy to announce the General Availability of Prisma Client extensions! Extensions have proven to be extremely useful and powerful during the Preview period, even powering Prisma products like Accelerate and Pulse!
A straightforward and easy to use API
If this is the first time you're hearing about Client extensions, don't worry. We have an existing blog post that covers the usage in-depth. To sum it up here: creating an extension is as easy as using $extends
.
This code snippet shows how you can add a new method to the User
model using a model
extension:
If you instead require a method on all models, you can even use the builtin $allModels
feature:
For a more in-depth look into changes we made to the extensions API as a part of this release, please check out our release notes
Extensions built by the community
While client extensions are now generally available, we have already seen some cool examples in the wild. prisma-extension-pagination
is an awesome contribution from our community. Importing and using an external client extension is easy too:
Reference examples for various use cases
In addition to community contributions, we have a set of reference examples in the prisma-client-extensions
example repository that showcase different areas where we believe Prisma Client extensions can be useful. The repository currently contains the following example extensions:
Example | Description |
---|---|
audit-log-context | Provides the current user's ID as context to Postgres audit log triggers |
callback-free-itx | Adds a method to start interactive transactions without callbacks |
computed-fields | Adds virtual / computed fields to result objects |
input-transformation | Transforms the input arguments passed to Prisma Client queries to filter the result set |
input-validation | Runs custom validation logic on input arguments passed to mutation methods |
instance-methods | Adds Active Record-like methods like save() and delete() to result objects |
json-field-types | Uses strongly-typed runtime parsing for data stored in JSON columns |
model-filters | Adds reusable filters that can composed into complex where conditions for a model |
obfuscated-fields | Prevents sensitive data (e.g. password fields) from being included in results |
query-logging | Wraps Prisma Client queries with simple query timing and logging |
readonly-client | Creates a client that only allows read operations |
retry-transactions | Adds a retry mechanism to transactions with exponential backoff and jitter |
row-level-security | Uses Postgres row-level security policies to isolate data a multi-tenant application |
static-methods | Adds custom query methods to Prisma Client models |
transformed-fields | Demonstrates how to use result extensions to transform query results and add i18n to an app |
exists-fn | Demonstrates how to add an exists method to all your models |
Show off your extensions!
If you'd like a deeper dive into Prisma Client extensions, be sure to check out our previous write-up: Prisma Client Just Became a Lot More Flexible: Prisma Client Extensions!
We'd also love to hear about your extensions (and maybe even take them for a spin).
Be sure to show of your #MadeWithPrisma
work in our Discord
Don’t miss the next post!
Sign up for the Prisma Newsletter