Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create soft-delete example #39

Open
nikolasburk opened this issue Nov 8, 2023 · 1 comment
Open

Create soft-delete example #39

nikolasburk opened this issue Nov 8, 2023 · 1 comment

Comments

@nikolasburk
Copy link
Member

Similar to Zenstack: https://zenstack.dev/blog/prisma-client-extensions#1-soft-delete

So that in the future we can share it with questions like this one: prisma/prisma#21704

@micobarac
Copy link

import { Prisma } from '@prisma/client';

export const softDeleteExtension = Prisma.defineExtension({
  name: 'soft-delete-extension',
  model: {
    $allModels: {
      async softDelete<M, A>(
        this: M,
        where: Prisma.Args<M, 'update'>['where']
      ): Promise<Prisma.Result<M, A, 'update'>> {
        const context = Prisma.getExtensionContext(this);
        return (context as any).update({
          where,
          data: {
            deletedAt: new Date()
          }
        });
      }
    }
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants