This example shows how to use Prisma Client extensions to perform similar tasks as middleware. In this example, a query
extension tracks the time it takes to fulfill each query, and logs the results along with the query and arguments themselves.
This technique could be used to perform generic logging, emit events, track usage, etc.
NOTE: The OpenTelemetry tracing and Metrics features (currently in Preview) can provide detailed insights into performance and how Prisma interacts with the database. This example shows how to use Prisma Client extensions to perform actions before or after queries, and is not a fully-featured logging / tracing solution.
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 query-logging
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