Is there a way to delete by filter ?
# prisma-whats-new
k
Is there a way to delete by filter ?
n
@kimf I updated this feature request to also include the delete case
oh well
are you saying you want to delete multiple items by specifying a filter
or do you want to delete a single item by specifying a filter
those two feature requests look relevant 🙂
k
Nice.. I have a 2 Types, one with 546 items and one associated one with 9584 records and there seems to have been some error when I imported them, so I need to clear them and the import again. So maybe a “Delete all data for Type” would be nice as well
n
yea that would be very useful. For now you could use a similar script to this: https://github.com/graphcool/feature-requests/issues/81#issuecomment-283961422
k
I just deleted the type and created it again, was easy enough thanks to the new schema view 😄
n
Hehe 🙂 Glad that works for now
s
what about something like this? first query all your id fields, then(scrubbed so something might look odd): const client = require('../../client') function buildMutation(thing){ return
Copy code
id_${thing.id}: deleteThing(
        id:	"${thing.id}",
        
      ) {
        id,
      },
} function deleteThings(things){ const mutationSet = things.reduce( (acc, item) => { const thisMutation = buildMutation(item); return acc.concat(thisMutation) }, '' ) const mutation =
Copy code
{
${mutationSet}
}
console.log('MUTATION SET', mutation); return client.mutate(mutation) .then(result => { return result }) } module.exports = deleteThings
👍 1
i was using that to create a bunch of things, but would assume delete would be no different
n
yea exactly! That's the same idea in the script that I linked above I guess