Dexie.js: bulkAdd() error catch 获取失败数据记录

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

如果我使用 bulkAdd() 向我的数据库添加一个 blob,那么如果任何键已经存在,它就会抛出错误提示相同。

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

现在我想,如果数据库中已经存在任何键,则使用一些 if 条件更新与该键关联的数据(例如,如果它小于 1)。
但是当我尝试 console.log(error.failures) 它只显示消息而不是数据对象。
谁能告诉我我们该怎么做?

使用 Table.bulkAdd() 如果主键已经存在,操作将失败。

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.

您可以使用 Table.bulkPut() 在重复键的情况下替换记录。

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.

您可以使用 table.bulkPut().

如果密钥不可用,则添加元素。如果可用,请更新值。而且速度更快。