You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Love the API, this will be so useful to build tooling! ❤️
Although most params in the middleware are self-explanatory, I was wondering what the dataPath & headers params stand for? (Perhaps we should add some documentation for these params?)
dataPath is for example when you do .user.findone().posts - then dataPath is ['posts'] headers shouldn’t even be there but are there so you can change the headers for a request to the query engine - only relevant for debugging
Awesome feature. It would be very nice to have some tooling to compare the model against a type instead of a string to avoid mistakes when refactoring/renaming.
The middleware is a nice feature, it would be nice if we could get the result for find queries and manipulate how data gets returned so that we can use the middleware for caching const someProp = redisClient.get(${params.args.where.id}:someProp);, if the key was found we could then prevent a database hit and return using data from the cache, otherwise we can run the query and save the result in the cache
What exactly do you mean @beeme1mr? The actual SQL queries are one level lower in the Prisma Engine that is executed by the Prisma Client. What you can see in the middleware is the Prisma Client query, which is sent over to the Prisma Engine for generation of SQL query(/ies).
@janpio thanks for the info on the logger. That will probably work for now.
It would be nice get the actual SQL query in the middleware though. Could I hook into the Prisma Engine to achieve this? Possibly manually construct a Document using middleware params.
Could I hook into the Prisma Engine to achieve this?
I am not sure that would be possible as engine also combines queries in a batch if they are executed in the same time frame to improve performance. Also, I don't think the client receive a document of generated query, right now when logging is enabled, the engine splits the log on the stdout.
Do you have any specific usecase in mind which you can't do with the current query logging system?
Activity
sdnts commentedon Jul 23, 2020
Love the API, this will be so useful to build tooling! ❤️
Although most
paramsin the middleware are self-explanatory, I was wondering what thedataPath&headersparams stand for? (Perhaps we should add some documentation for these params?)For reference, this is my middleware:
and here are all params logged:
sdnts commentedon Jul 23, 2020
From Slack discussion:
Sytten commentedon Jul 23, 2020
Awesome feature. It would be very nice to have some tooling to compare the model against a type instead of a string to avoid mistakes when refactoring/renaming.
julienp commentedon Jul 26, 2020
janpio commentedon Jul 26, 2020
abhiaiyer91 commentedon Jul 27, 2020
janpio commentedon Jul 27, 2020
daniellwdb commentedon Jul 31, 2020
The middleware is a nice feature, it would be nice if we could get the result for find queries and manipulate how data gets returned so that we can use the middleware for caching
const someProp = redisClient.get(${params.args.where.id}:someProp);, if the key was found we could then prevent a database hit and return using data from the cache, otherwise we can run the query and save the result in the cachesdnts commentedon Jul 31, 2020
@pandaniell You should be able to do that already if I understood you correctly. Here's an example:
Essentially, requests go out only if you
awaitthenextfunction. Give that a shot?daniellwdb commentedon Jul 31, 2020
@madebysid Thank you, I didn't think of trying to return something else other than next, working example using Redis
sdnts commentedon Jul 31, 2020
Nice! You should wrap it up in a usable package and add it here if you'd like: https://github.com/catalinmiron/awesome-prisma :D
daniellwdb commentedon Aug 1, 2020
Would be a nice alternative to #3165 - unfortunately I lack the knowledge to make that work but maybe somebody else is interested
janpio commentedon Aug 1, 2020
Open a new issue @pandaniell for "query caching middleware" and we can discuss if this might already be possible, what is missing and so on.
abhiaiyer91 commentedon Aug 1, 2020
I implemented a query caching middleware with LRUCache here https://github.com/abhiaiyer91/prisma-lrucache-middleware
beeme1mr commentedon Aug 12, 2020
Is it possible to see the query Prisma generated in the middleware? I would like to use this for monitoring purposes.
janpio commentedon Aug 12, 2020
What exactly do you mean @beeme1mr? The actual SQL queries are one level lower in the Prisma Engine that is executed by the Prisma Client. What you can see in the middleware is the Prisma Client query, which is sent over to the Prisma Engine for generation of SQL query(/ies).
To see the actual SQL queries, you can use logging: https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/logging Via the event based logging, that can be used in a similar way as the middleware: https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/logging#event-based-logging
beeme1mr commentedon Aug 12, 2020
@janpio thanks for the info on the logger. That will probably work for now.
It would be nice get the actual SQL query in the middleware though. Could I hook into the Prisma Engine to achieve this? Possibly manually construct a
Documentusing middleware params.pantharshit00 commentedon Aug 12, 2020
I am not sure that would be possible as engine also combines queries in a batch if they are executed in the same time frame to improve performance. Also, I don't think the client receive a document of generated query, right now when logging is enabled, the engine splits the log on the stdout.
Do you have any specific usecase in mind which you can't do with the current query logging system?
janpio commentedon Aug 13, 2020
This is exactly what using the logger is doing. You can do whatever you want with these events that are triggered.
nikolasburk commentedon Aug 18, 2020
Thanks a lot for all of your feedback, we've just promoted this future into the latest stable 2.5.0 release 🙌