dexie / Dexie.js

A Minimalistic Wrapper for IndexedDB
https://dexie.org
Apache License 2.0
11.49k stars 642 forks source link

Multiple unique constraints and duplicates #1759

Open bokolob opened 1 year ago

bokolob commented 1 year ago

Hello!

My collection should have multiple unique keys, is there a way to ignore duplicates when insert? Both put and add calls throw exception. The only way I think about - start transaction and filter out existing elements, but I suppose it’s slower.

Thanks.

dfahlander commented 1 year ago

Use [bulkPut()](https://dexie.org/docs/Table/Table.bulkPut()) or [bulkAdd()](https://dexie.org/docs/Table/Table.bulkAdd()) and catch the resulting promise explicitely (using returnPromise.catch(), not try... await...catch). This way the duplicates will be silently ignored while the other ones shall succeed.