1.0.2 • Published 1 year ago

prisma-model-events-extension v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Prisma Model Events Extension

Disclaimer

This Prisma client extension is heavily inspired by the AvantaR/prisma-event-dispatcher. Since middlewares are deprecated since version 4.16.0., this replaces it with a query extension.

Installation

npm i prisma-model-events-extension

Usage

const client = new PrismaClient().$extends(
    PrismaModelExtension.setup(config).getExtension(),
);

Configuration

To use the extension, you have to pass an array of configuration objects per model of the following form:

interface ModelEventsConfig {
    model: string; // your model name
    actions: PrismaAction[]; // an array of supported Prisma operations;
    when: When[]; // 'before', 'after'
}

Supported Prisma operations

| 'findUnique'
| 'findMany'
| 'findFirst'
| 'create'
| 'createMany'
| 'update'
| 'updateMany'
| 'upsert'
| 'delete'
| 'deleteMany'
| 'executeRaw'
| 'queryRaw'
| 'aggregate'
| 'count'

Behaviour

Ths extension uses the eventemitter2 package and emits events named as such (all lowercase):

when.model.operation; // e.g. before.user.findmany or after.user.create

Feel free to listen to them elsewhere in your code.

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago