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!
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
This code snippet shows how you can add a new method to the
User model using a
If you instead require a method on all models, you can even use the builtin
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
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:
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:
|Provides the current user's ID as context to Postgres audit log triggers
|Adds a method to start interactive transactions without callbacks
|Adds virtual / computed fields to result objects
|Transforms the input arguments passed to Prisma Client queries to filter the result set
|Runs custom validation logic on input arguments passed to mutation methods
|Adds Active Record-like methods like
delete() to result objects
|Uses strongly-typed runtime parsing for data stored in JSON columns
|Adds reusable filters that can composed into complex where conditions for a model
|Prevents sensitive data (e.g. password fields) from being included in results
|Wraps Prisma Client queries with simple query timing and logging
|Creates a client that only allows read operations
|Adds a retry mechanism to transactions with exponential backoff and jitter
|Uses Postgres row-level security policies to isolate data a multi-tenant application
|Adds custom query methods to Prisma Client models
|Demonstrates how to use result extensions to transform query results and add i18n to an app
|Demonstrates how to add an exists method to all your models
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).
Don’t miss the next post!
Sign up for the Prisma Newsletter