Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use Web SQL verus IndexedDB? [closed]

Tags:

Recently, I have come across the Web SQL and IndexedDB APIs that are provided by browsers. What are the use cases for Web SQL and IndexedDB and when should I use one over the other?

like image 994
Utsav Sinha Avatar asked Sep 26 '17 06:09

Utsav Sinha


2 Answers

Web SQL is deprecated per https://www.w3.org/TR/webdatabase/.

You can use IndexedDB if you need to store structured client specific data that you do not store in the server side or you do not want to request from the server every time.

Also as opposed to localStorage, IndexedDB is async so it is more performant. It supports indexing resulting in more efficient querying than localStorage which is simply a key-value store. However, if your needs are simple, localStorage might be a better option.

Here is a link that talks about different web storage options. Here is a tutorial about how to use IndexedDB for a progressive web app.

like image 151
Hakan Avatar answered Sep 21 '22 08:09

Hakan


Why not Web SQL?

The Web SQL database specification has been deprecated since November 2010. The browser vendors are not encouraged to support this technology and it's important that anyone reading this understands this. You can read more about Web SQL on its Wikipedia page. Now back to the other important segment of your question.

When to use the IndexedDB API?

You can use IndexedDB to store data of any JavaScript type, such as an object or array, without having to serialize it. All requests against the database are asynchronous. The browser's implementation allows you to set callbacks for when successes or errors occur. Modern abstractions over this implementation allow you to use promises instead.

One of the major use cases for IndexedDB is creating an offline database that will be synchronized with the actual database once online. This allows an application to continue to work while offline and persist past reloads. A now-dead famous example of this is Wunderlist, you can add and edit tasks even when offline. These operations go in a synchronization queue which is processed and emptied when the network is available again. This is how a lot of to-do list applications work when offline.

like image 29
Blessed Jason Mwanza Avatar answered Sep 20 '22 08:09

Blessed Jason Mwanza