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
Within the "onModuleInit" function i registered a middleware:
/** * Init prisma and attach DB history log * */asynconModuleInit(){awaitthis.$connect();this.$use(async(parameters: Prisma.MiddlewareParams,next)=>{// DO STUFF});}
With prisma 4.16.0 "$use" became deprecated and the replacement:
Deprecated: Middleware is deprecated in version 4.16.0.
We recommend using the Prisma Client extensions query component type as an alternative to middleware. Prisma Client extensions were first introduced into Preview in version 4.7.0 and made Generally Available in 4.16.0.
Prisma Client extensions allow you to create independent Prisma Client instances and bind each client to a specific filter or user. For example, you could bind clients to specific users to provide user isolation. Prisma Client extensions also provide end-to-end type safety.
Right now i made a hack that basically graps the extended client from a base class thats provides the extension:
exportclassPrismaServiceextendsPrismaBasicServiceimplementsOnModuleInit{constructor(privatemoduleReference: ModuleRef,
@Inject(WINSTON_MODULE_NEST_PROVIDER)localLogger: WinstonLogger,// @Inject(forwardRef(() => PrismaBasicService))){super(moduleReference,localLogger);}/** * We want to use the extended prisma service from PrismaBasicService * Therefore we fetch it from the module reference and overwrite the class with the extended service * */asynconModuleInit(){constprismaBasic=this.moduleReference.get(PrismaBasicService,{strict: false});Object.assign(this,prismaBasic.extendedClient);}}
Not nice. Is there a better way to do that i am currently missing?
Describe the solution you'd like
A way to make the injected prisma service to execute on the extend client if exists.
Maybe a function that allows to inject the extend clients instance. Or something completely different that give the ability to make use of the extend client in a more convenient way.
What is the motivation / use case for changing the behavior?
Changing all usages of prima with the extended client is not convenient.
The text was updated successfully, but these errors were encountered:
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
I have a prisma service along the lines of the offical documentation: https://docs.nestjs.com/recipes/prisma#use-prisma-client-in-your-nestjs-services
Within the "onModuleInit" function i registered a middleware:
With prisma 4.16.0 "$use" became deprecated and the replacement:
https://www.prisma.io/docs/concepts/components/prisma-client/middleware
Could to the stuff. However it will provide a new extended instance of the client and i would need to refactor all usages that currently rely on:
To something like:
Right now i made a hack that basically graps the extended client from a base class thats provides the extension:
Not nice. Is there a better way to do that i am currently missing?
Describe the solution you'd like
A way to make the injected prisma service to execute on the extend client if exists.
Teachability, documentation, adoption, migration strategy
Maybe a function that allows to inject the extend clients instance. Or something completely different that give the ability to make use of the extend client in a more convenient way.
What is the motivation / use case for changing the behavior?
Changing all usages of prima with the extended client is not convenient.
The text was updated successfully, but these errors were encountered: