Watermelondb: Database records batch delete

Created on 22 Jan 2020  路  4Comments  路  Source: Nozbe/WatermelonDB

Hi, I've noticed an issue where it's not possible to delete multiple records at the same time.

For example, the follwing code deletes records one by one:

db.collections.get('comments').query().destroyAllPermanently()

Is it possible to delete multiple records at the same time?

Most helpful comment

I dug up the solution:

const comments = await db.collections
  .get('comments')
  .query()
  .fetch()

const deleted = comments.map(comment => comment.prepareDestroyPermanently())

db.batch(...deleted)

All 4 comments

Same problem

I dug up the solution:

const comments = await db.collections
  .get('comments')
  .query()
  .fetch()

const deleted = comments.map(comment => comment.prepareDestroyPermanently())

db.batch(...deleted)

Exellent job!

@NikolaMasulovic @markorusic Check out record.experimentalDestroyPermanently() -- this will delete record & all its children

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arambrosius picture arambrosius  路  8Comments

impactcolor picture impactcolor  路  4Comments

K4stor picture K4stor  路  7Comments

ymahnovskyy picture ymahnovskyy  路  5Comments

bsr203 picture bsr203  路  6Comments