-
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
Lifecycle hooks for crud operations. #9684
Comments
Hey there. I think you could build this with middlewares already. However, we will be bringing a way to write custom extensions for Prisma Client. I see this one could be built directly via |
This is really useful. Probably is also the only reason I can't use Prisma |
Hi @dzcpy, would you be able to elaborate why middlewares aren't meeting your expectations specifically? That would help to understand the differences which may exist between them and what you imagine this feature request to be. |
Hi @thebiglabasky, thanks for your reply. I'm building an ecommerce platform using nestjs. There are a lot of enttities like orders, products, users etc., they are written in different modules. For a lot of them, I need to create lifecycle hooks, for example before updating some records, I'll do basic data validation, change the data user has input and then update some other entities. So basically my needs can be concluded as the following:
For 2 and 4 it's better to put them in one place because in some cases, I'll need to change other records even when validation has failed Also, I would like it to be modular because there are too many entities, using middleware to do it seems to be a bit inconvinient in term of maintainability. And if I use a midduleware for each single entities it's kind of cumbersome that if I update an entity then all other middlewares which don't have anything to do with this entity will still be run. I'm new to Prisma so I'm not sure if there's already some ways to do it (elegantly). If so, it would be awesome to have some examples for Prisma beginners like me to learn. Thanks! |
Thanks for the additional details 🙏 |
Problem
Sometimes there's a need to run certain function before a record is added or maybe create another record or execute certain workflow after a record is created/deleted (eg: trigger websocket events), and it is useful to have away to tap into those lifecycle events.
Alternatives
Strapi has a great way of handling lifecycle events. Linking doc here.
The text was updated successfully, but these errors were encountered: