Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between add and put in indexeddb?

Tags:

indexeddb

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

like image 883
amol01 Avatar asked Dec 08 '14 11:12

amol01


People also ask

How many API modes IndexedDB have?

Before creating the database I want to tell you about the two API modes of IndexedDB. Synchronous mode: This mode was created to be used only in conjunction with web workers. But most browsers currently do not support the synchronous mode.

What is keyPath in IndexedDB?

The keyPath read-only property of the IDBObjectStore interface returns the key path of this object store. If this property is null, the application must provide a key for each modification operation.

Is IndexedDB deprecated?

The W3C has announced that the Web SQL database is a deprecated local storage specification so web developer should not use this technology any more. indexeddb is an alternative for web SQL data base and more effective than older technologies.


1 Answers

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."

like image 138
Deni Spasovski Avatar answered Sep 28 '22 09:09

Deni Spasovski