Search code examples
node.jsindexeddbdexie

Dexie.js: get failures data records in bulkAdd() error catch


If I add a blob to my database using bulkAdd(), then if any key already exist then it throw error saying same.

bulkAdd(): 127 of 127 operations failed. 
Errors: ConstraintError: Key already exists in the object store.

Now I want, if any key already exist in database then update data associated with that key using some if condition (e.g. if it is smaller than 1).
But when I try to console.log(error.failures) it just shows messages not the data object.
Can any one tell me how we can do that?


Solution

  • With Table.bulkAdd() the operation will fail if there is a primary key that already exists.

    Table.add()

    Adds an object to the object store.

    Remarks

    Add given object to store. If an object with the same primary key already exist, the operation will fail and returned promise catch() callback will be called with the error object.

    You can use Table.bulkPut() for replacing records in a case of duplicate keys.

    Table.put()

    Adds new or replaces existing object in the object store.

    Remarks

    If an object with the same primary key already exists, it will be replaced with the given object. If it does not exist, it will be added.