Skip to content

Latest commit

 

History

History
 
 

query-logging

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Prisma Client Extension - Query Logging

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.

Caveats

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.

How to use

Prerequisites

1. Download example & install dependencies

Clone this repository:

git clone [email protected]:sbking/prisma-client-extensions.git

Install dependencies:

cd query-logging
npm install

2. Create an SQLite database and run migrations

Run the following command. An SQLite database will be created automatically:

npx prisma migrate deploy

3. Seed the database

Run the following command to add seed data to the database:

npx prisma db seed

4. Run the dev script

To run the script.ts file, run the following command:

npm run dev