-
-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
How to configure when using CustomPrismaModule.forRootAsync #96
Comments
Hey @JinJieBeWater, because you have full control over the // prisma.extension.ts
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
// apply middleware with `$use` 👇
prisma.$use(loggingMiddleware());
prisma.$use(...); // as many as you want
// now extend the PrismaClient
export const extendedPrismaClient = prisma
.$extends({
model: {
user: {
findByEmail: async (email: string) => {
console.log('extension findByEmail');
return extendedPrismaClient.user.findFirstOrThrow({
where: { email },
});
},
},
},
})
export type ExtendedPrismaClient = typeof extendedPrismaClient;
// app.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { CustomPrismaModule } from 'nestjs-prisma';
import { extendedPrismaClient } from './prisma.extension';
@Module({
imports: [
CustomPrismaModule.forRootAsync({
name: 'PrismaService',
useFactory: () => {
return extendedPrismaClient;
},
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {} |
On this note, Prisma deprecated middleware in favor of extensions query. Maybe it would be good to provide the Let me know what you think and if the above works for you. |
Oh, thank you for taking the time to help me, using extensions query is a good idea, I learned a lot, maybe I should look at these examples again, my problem has been solved, thank you for your help |
How to configure when using CustomPrismaModule.forRootAsync, for example
prismaServiceOptions: {
middlewares: [loggingMiddleware()]
},
The text was updated successfully, but these errors were encountered: