Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prisma deleteMany with a list of IDs

I'm wondering if there is a way in the Prisma Client to batch delete database records by id.

Something like this doesn't seem to exist:

const idsToDelete = [5, 29, 255]

prisma.post.deleteMany({
    where: {
        id: {
            equals: idsToDelete
        }
    }
})

The docs allude to the concept of Scalar List Filters, but this doesn't seem to be supported for numeric lists or perhaps isn't supported in deleteMany.

Under the hood, I'm hoping for a SQL DELETE ... WHERE IN clause. I'd prefer not to:

  • Spin up a bunch of individual JS promises
  • Use database-specific Prisma features (ok if it's not supported in MongoDB)
  • Write SQL directly
like image 928
Nate Vaughan Avatar asked Nov 17 '25 02:11

Nate Vaughan


1 Answers

You can use the in operator:

    where: {
        id: {
            in: idsToDelete
        }
    }
like image 159
timewastingprofessional Avatar answered Nov 18 '25 18:11

timewastingprofessional



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!