Replies: 9 comments
-
We need this feature too. We are migrating from TypeORM so something like the TypeORM listeners/subscribers would be ideal: |
Beta Was this translation helpful? Give feedback.
-
Would love to have this. Prisma's middleware applies to all requests. Not very good separation of concern and unnecessarily inefficient. It doesn't have to be fully implemented as signals in Django. Simple pre and post hooks that are definable with the model would work too. |
Beta Was this translation helpful? Give feedback.
-
@ivanjd I'm curious what are your reasons for leaving TypeORM? |
Beta Was this translation helpful? Give feedback.
-
The functionality that developers can extend their drizzle client like prisma client extension. Scenarios that I have faced:
|
Beta Was this translation helpful? Give feedback.
-
From what I understand the team is looking into implementing middleware #1513 (comment) |
Beta Was this translation helpful? Give feedback.
-
We currently wrap drizzle in a base repository https://gist.github.com/cayter/49d5c256a885d90c399ca6c1eca19f51 which it will trigger the before and after hooks. Note that we only made it working with postgres. |
Beta Was this translation helpful? Give feedback.
-
Will it be supported officially in the future? This is probably the only reason why I can't use Drizzle ORM |
Beta Was this translation helpful? Give feedback.
-
@AndriiSherman If you write the reason for not turning this issua into a discussion, it will be more explanatory. We are now in a dilemma between not knowing what will happen. |
Beta Was this translation helpful? Give feedback.
-
Hello Drizzle maintainers,
Firstly, I'd like to take a moment to appreciate all the effort that goes into maintaining and improving Drizzle. It's an incredibly valuable resource and it has made development a lot easier for me.
Summary
I would like to suggest a feature for the library: Pre & Post Save Signals, similar to the signals mechanism found in Flask or Django, or the middleware concept in Prisma.
Problem
In the current version of Drizzle, there is no in-built mechanism for triggering actions before or after a database query. Although we can manually code this logic around the Drizzle function calls in our application, it introduces additional complexity, scattered code and it’s also more error-prone. Furthermore, some tasks naturally belong to the ORM layer, such as data validation, logging, or automated reactions to data changes.
I do acknowledge that Drizzle already provides a comprehensive logging feature, which is highly versatile and configurable, allowing us to write logs anywhere desired - disk, API, etc. However, the feature I am proposing is conceptually different. While logging captures and records the state of the system at a given point of time, pre and post save signals would enable automated, direct response to these state changes, beyond just recording them.
Suggested solution
By introducing Pre & Post Save Signals, users of Drizzle would have a way to hook into the lifecycle of a model instance, allowing them to define tasks that should be performed before or after saving a record.
For example, a common use case could be sending a welcome email to a new user after a new row is created in the User table. With the suggested mechanism, one could define a 'post save' signal on the User model that automatically sends an email when a new instance of User is saved to the database.
Benefit to the Drizzle users
Such a feature would enable developers to manage side-effects more effectively by linking them directly to model lifecycle events. This would improve readability, maintainability, and reduce the likelihood of errors as changes in state can be handled at the moment they occur. It provides a clean and intuitive solution to manage a range of common tasks such as sending notifications, logging, data validation, etc.
I hope you'll consider this feature request for inclusion in a future version of Drizzle. I believe it could add a great deal of flexibility and improve the developer experience significantly.
References
Beta Was this translation helpful? Give feedback.
All reactions