Search code examples
javascriptindexeddbofflineappsdexie

Dexie: difference bulkPut and BulkAdd


I have checked the Documentation, but there seems to be no difference between using bulkPut and bulkAdd.

Yet I noticed that when I try to use bulkAdd with a list of events including one that I previously deleted, it does not add this event. If I use bulkPut it does add the event.

I would like to have a better understanding of the difference between this two methods.

Thanks


Solution

  • bulkAdd() will fail to add any item with same primary key whilst bulkPut () will succeed and update those records as well as the new ones. If you do bulkAdd () within a transaction and don't catch the operation explicitly, the entire transaction will fail and roll back if any one item has an existing primary key. Catching the bulkAdd () will make sure any successful operation succeeds while failed operations are just ignored.