What is the difference between add and put in indexeddb?

倾然丶 夕夏残阳落幕 提交于 2019-12-21 03:42:42

问题


I am just starting to use indexeddb and transforming Web SQL.

I tried to use add and put to add some data in data store. I could not really see what is/are the difference/s of using these two functions.

I think I have to know the difference so I could use them appropriately.

Thanks forward


回答1:


The difference between add and put is same as in any API.

If you try to insert an element with key that already exist using the put function it will trigger and update of the existing element, however if you use the add function and element with same id exist you will get an error with the following message: "Key already exists in the object store."



来源:https://stackoverflow.com/questions/27357391/what-is-the-difference-between-add-and-put-in-indexeddb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!