nestjs-prisma
nestjs-prisma copied to clipboard
How do I enable logging with CustomPrismaModule?
I am utilising the CustomPrismaModule
in order to make use of client extensions. I have a file prisma.extension.ts
that has the following code:
export const extendedPrismaClient = new PrismaClient<
Prisma.PrismaClientOptions,
'query' | 'info' | 'warn' | 'error'
>({
log: [
{ level: 'query', emit: 'event' },
{ level: 'info', emit: 'event' },
{ level: 'warn', emit: 'event' },
{ level: 'error', emit: 'event' },
],
}).$extends({
model: {
...
},
});
export type ExtendedPrismaClient = typeof extendedPrismaClient;
This is then instantiated in my app.module.ts
file:
imports: [
CustomPrismaModule.forRootAsync({
name: 'PrismaService',
isGlobal: true,
useFactory: () => {
return extendedPrismaClient;
},
}),
According to the docs I need to add the following to my main.ts
file:
async function bootstrap() {
const app = await NestFactory.create(AppModule);
// log query events
const prismaService: PrismaService = app.get(PrismaService);
prismaService.$on('query', (event) => {
console.log(event);
});
However, this results in the following error:
Nest could not find PrismaService element (this provider does not exist in the current context)