-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add model event listeners to execute code before or after inserting/updating models #22533
Comments
Hi @MichaelNZ85, this should already be possible via Prisma's The idea is that you can create wrappers for certain operations within Prisma itself, so you can add your own custom logic before or after Prisma executes that query. You can add logs, modify Prisma filters, invoke async operations tied to your own business logic, and so on. Please give it a try and let us know whether this information is enough to close this issue :) |
I gave it a try and found that it is not possible to create
Then I tried the following:
Both variants failed to find the user we just created in the DB and the calculation on it is impossible. Although I found that prisma does not commit the transaction until the extended Please let us know if there is a solution for |
Problem
There is no simple way to listen to lifecycle events on models (creating, updating etc). This is possible in TypeORM with entity listeners/subscribers such as
@BeforeInsert
and in Laravel with Eloquent events.Suggested solution
Allow users to listen to lifecycle events, either in the schema or in the Prisma client. Something like this (adding a standard user role to a newly created user):
Alternatives
Custom functions could be created to accomplish this, but it would be easier if every time a model is created or updated, the necessary code is run.
Prisma is great, but without this feature I will not be using it.
The text was updated successfully, but these errors were encountered: