@prisma-extensions/soft-delete
Version:
Soft Delete can be used to hide records instead of deleting them, making them recoverable later.
33 lines (32 loc) • 1.02 kB
JavaScript
import { Prisma } from '@prisma/client';
import { softDelete, softDeleteMany, softRestore, softRestoreMany } from './mutations';
import { scopedQuery } from './queries';
const defaultConfig = {
models: ['$allModels'],
};
export const applyExtension = (config) => {
const { models } = { ...defaultConfig, ...config };
return Prisma.defineExtension({
name: '@prisma-extensions/soft-delete',
query: Object.fromEntries(models.map((model) => [
model,
{
aggregate: scopedQuery,
count: scopedQuery,
findFirst: scopedQuery,
findFirstOrThrow: scopedQuery,
findMany: scopedQuery,
groupBy: scopedQuery,
},
])),
model: Object.fromEntries(models.map((model) => [
model,
{
softDelete,
softDeleteMany,
softRestore,
softRestoreMany,
},
])),
});
};