gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 12:14:56 25 4
gpt4 key购买 nike

如果我使用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.

关于node.js - Dexie.js : get failures data records in bulkAdd() error catch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60900347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com