This example uses Prisma Client extensions to perform custom runtime validations when creating and updating database objects.
This technique could be used to sanitize user input or otherwise deny mutations that do not meet some criteria.
NOTE: Query extensions do not currently work for nested operations. In this example, validations are only run on the top level
data
object passed to methods such asprisma.product.create()
. Validations implemented this way do not automatically run for nested writes.
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.git
Install dependencies:
cd input-validation
npm install
Run the following command. An SQLite database will be created automatically:
npx prisma migrate deploy
To run the script.ts
file, run the following command:
npm run dev