This example demonstrates how to create a Prisma Client extension that adds virtual / computed fields to a Prisma model. These fields are not included in the database, but rather are computed at runtime.
Computed fields are type-safe and may return anything from simple values to complex objects, or even functions that can act as methods for your models.
Computed fields must specify which other fields they depend on, and they may be composed / reused by other computed fields.
This extension is provided as an example only. It is not intended to be used in production environments.
Please read the documentation on result
extensions for more information.
- Install Node.js
Clone this repository:
git clone [email protected]:sbking/prisma-client-extensions.git
Install dependencies:
cd computed-fields
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