npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

prisma-cascade-delete

v1.0.2

Published

Package that exports a function to cascade-delete records in prisma v2

Readme

Prisma Cascade Delete

Prisma (v2) is one of the hottest ORM's right now (you can see some of the reasion I think so here). It still has some important holes, though. Cascade delete is one of the most proeminent ones, and most of the "automatic" workarounds have some issue.

This package exposes a cascadeDelete function that uses the information available at the prisma models to perform cascade deletes on one-to-many and many-to-many (with a relation table) relations. The cascade goes as deep as the relation goes (see example below).

Installation

npm install prisma-cascade-delete

Usage

import { cascadeDelete } from "prisma-cascade-delete";

cascadeDelete(prisma, modelName, where);
// prisma is the prisma-client instance from your app
// modelName must be the same as used in the prisma schema (e.g. "User")
// where is an object accepted by prisma queries as a *where* statement

Example

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        Int      @id @default(autoincrement())
  title     String
  content   String?
  published Boolean  @default(false)
  viewCount Int      @default(0)
  author    User    @relation(fields: [authorId], references: [id])
  authorId  Int
}

model Tag {
  id        Int      @id @default(autoincrement())
  name      String
}

model TagsInPost {
    id       Int     @id @default(autoincrement())
    post     Post    @relation(fields: [postId], references: [id])
    postId   Int
    tag      Tag     @relation(fields: [tagId], references: [id])
    tagId    Int

}

In the schema above, we would expect that if we delete a User, all its Posts and all the Tags associated to this posts would be deleted as well. However, there is no way to set this up.

That's where cascadeDelete comes in;

import { cascadeDelete } from "prisma-cascade-delete";
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

cascadeDelete(prisma, "User", { id: 1 });

This function will generate

const userDelete = prisma.user.delete({ where: { id: 1 } });
const postsDelete = prisma.post.deleteMany({ where: { userId: 1 } });
const postTagDelete = prisma.tagsInPost.deleteMany({
  where: { OR: [{ postId: 1 }, { postId: 2 }] },
}); 
// Imagining that the user posted posts 1 and 2

prisma.$transaction([postTageDelete,postsDelete,userDelete])