P
Prisma2mo ago
pMullot

Is "daisy-chaining Extensions" a good practice?

Hi, I need to execute many dependent processes upon "update" of my "users" table. For that, I understand the best option is to use Prisma Extensions. However, since each of these processes requires a fair amount of code, I'd like to separate them in different files, in order not to put everything inside the query.ysers.update block
query: {
users: {
async update({args, query}) => {
// do stuff here
}
}
}
query: {
users: {
async update({args, query}) => {
// do stuff here
}
}
}
The easiest way to proceed would be to extract each process inside its own function, but I'm having a really hard time to declare those functions with type safety, because of the type the args and query variables, as well as the return type. Another option would be to define several extensions and then daisy chain them like this: new PrismaClient().$extends(userExtension1).$extends(userExtension2) The issue with this technique is that I will probably end up executing the query in each extension, leading to unnecessary overload of the database. What are your recommendations? NB: I'm following those guidelines to write my extensions: https://www.youtube.com/watch?v=j5LU6q38E-c&t=627s
Prisma
YouTube
How To Build a Prisma Client Extension
Prisma Client extensions are a powerful way to add functionality to your Prisma Client. In this video, we deeply dive into what Prisma Client extensions are and how to build one. Repo with code from the tutorial https://github.com/sabinadams/prisma-field-picker 00:00 - How To Build a Prisma Client Extension 00:41 - What are Prisma Client Exte...
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server