How to extends the client for adding soft delete features currently this is not working how to fix ?
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import { prismaExtendedClient } from './extension';
@Injectable()
export class PrismaService
extends PrismaClient
implements OnModuleInit, OnModuleDestroy
{
readonly extendedClient = prismaExtendedClient(this);
constructor() {
super();
new Proxy(this, {
get: (target, property) =>
Reflect.get(
property in this.extendedClient ? this.extendedClient : target,
property,
),
});
}
async onModuleInit() {
await this.$connect();
}
async onModuleDestroy() {
await this.$disconnect();
}
}.
import { PrismaClient } from '@prisma/client';
export const mediaExtension = {
query: {
$allModels: {
async findMany({ model, operation, args, query }) {
const results = await query(args);
console.log('doees this even woirk....');
if (args.include?.media === true) {
return results.map((result) => ({
...result,
media: result.media.map((media) => ({
...media,
url:
https://baseurl.com/${media.name}
,
})),
}));
}
return results;
},
},
},
}; import { PrismaClient } from '@prisma/client';
import { softDelete } from './soft-delete';
import { mediaExtension } from './media.extension';
export const prismaExtendedClient = (prismaClient: PrismaClient) =>
prismaClient.$extends({
model: {
$allModels: {
softDelete,
},
media: mediaExtension,
},
});3 Replies
Please don’t tag moderators unless there’s an issue of safety.
how to solve that ?
Did you try this?
https://github.com/olivierwilkinson/prisma-extension-soft-delete
GitHub
GitHub - olivierwilkinson/prisma-extension-soft-delete: Prisma exte...
Prisma extension for adding soft delete to Prisma models, even when using nested queries - GitHub - olivierwilkinson/prisma-extension-soft-delete: Prisma extension for adding soft delete to Prisma...