Using NestJS with Prisma (Postgres)
this.$use function is indicated as deprecated, how to replace the following code with Prisma Extension ?
PrismaService.ts :
import { Injectable, OnModuleInit, OnModuleDestroy, Inject } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import { Cache } from 'cache-manager';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
constructor(@Inject(CACHE_MANAGER) private cacheManager: Cache) {
super();
}
async onModuleInit() {
await this.$connect();
this.$use(async (params, next) => {
if (params.model === 'User' && params.action === 'update') {
// Delete cache user info
const key = `user:${params.args.where.id}`;
await this.cacheManager.del(key);
}
return next(params);
});
}
async onModuleDestroy() {
await this.$disconnect();
}
}
Deprecated :