This example creates an adminPrisma client instance, as well as an extended publicPrisma client instance. The publicPrisma client automatically restricts queries to only include published posts.
This extension also uses the extendedWhereUnique preview flag to allow filtering on non-unique fields like published in methods like findUnique.
Currently, query extensions allow you to modify the arguments passed to Prisma Client methods like findMany which do not affect the return type, such as where, take, and skip. This allows you to customize how queries are run and filter down the result set.
NOTE: Query extensions do not currently work for nested operations. In this example, the
publicPrismaclient will only filter out unpublished posts when calling a top levelpostmethod such aspublicPrisma.post.findMany. It won't filter out posts that are included as relations of another model with nested reads usingincludeorselect.
This extension is provided as an example only. It is not intended to be used in production environments.
Please read the documentation on query extensions for more information.
- Install Node.js
Clone this repository:
git clone git@github.com:sbking/prisma-client-extensions.gitInstall dependencies:
cd input-transformation
npm installRun the following command. An SQLite database will be created automatically:
npx prisma migrate deployRun the following command to add seed data to the database:
npx prisma db seedTo run the script.ts file, run the following command:
npm run dev