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
publicPrisma
client will only filter out unpublished posts when calling a top levelpost
method such aspublicPrisma.post.findMany
. It won't filter out posts that are included as relations of another model with nested reads usinginclude
orselect
.
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 [email protected]:sbking/prisma-client-extensions.git
Install dependencies:
cd input-transformation
npm install
Run the following command. An SQLite database will be created automatically:
npx prisma migrate deploy
Run the following command to add seed data to the database:
npx prisma db seed
To run the script.ts
file, run the following command:
npm run dev