Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syncing IndexedDB with Sql Server

I am doing offline DB connectivity in my page using HTML5 IndexedDB concepts.. But Initially, I want to fetch large datas to store it in my IndexedDb, so for that purpose, I am trying to sync Sql Server Data to my IndexedDb Datatbase but I didnt find any solution to do that.. Is there any way to do that, If so Pls help me.. thank you..

like image 307
Manikandan Krishnamoorthy Avatar asked Mar 12 '14 05:03

Manikandan Krishnamoorthy


People also ask

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.

Is IndexedDB relational database?

IndexedDB is not a relational database with tables representing collections of rows and columns. This important and fundamental difference affects the way you design and build your applications.

Is IndexedDB fast?

Not slow like a database on a cheap server, even slower! Inserting a few hundred documents can take up several seconds. Time which can be critical for a fast page load.


2 Answers

In addition to Editor and Kristof answers, I would like to add few more things since I've worked on a similar solution.

  • First of as Editor said IndexedDB is a document-oriented database while SQL is relational database which means that the you should convert your data to a object model before storing them locally
  • Avoid using multiple tables in IndexedDB and trying to create joins.
  • Additional tables in IndexedDB should be used if you store different objects in the database or you have additional data for your main object (example list of articles in one table - article text in the second table).

Next thing is data synchronization - this can get really complicated if you update the data on both sides (client & server). The main problem that you'll be facing in the data synchronization is the fact that you'll have one main SQL database and a lot of local client databases.

Here are couple things you should also consider:

  • You'll need to pick when to do the synchronization timed or by client request.
  • One other question that pops up is: What if the user works a lot of the time in the offline mode and updates an object which has been previously deleted by another user and that's stored to the SQL database.
  • And of course when you sync the data, split it into chunks, this will reduce the size of each response and IndexedDB works faster with smaller transactions.
  • I currently sync 500 items at a time (adjust this to the size of your objects)
  • Also in Chrome you can access IndexedDB from web-workers and make parallel requests - this can really speed things up.

This are just some facts you'll need to consider before you start implementing the solution, hope it helps.

like image 146
Deni Spasovski Avatar answered Sep 21 '22 11:09

Deni Spasovski


From what I understand in your question, you are just using indexeddb like a cache layer in case the db goes done. What I would do is the following.

In case you are working online a save of your data should exist out af 2 actions. Saving to your service (SQL server) and save to your indexeddb.

In case when you are offline I would do 2 operation. On is still updating your indexeddb, but I would add an extra object store where you save all of your operation that have to be preformed on your service. Once back online, you can processes them one by one.

like image 30
Kristof Degrave Avatar answered Sep 23 '22 11:09

Kristof Degrave