Search code examples
javascripthtmlweb-sqlindexeddbofflineapps

Conversion from WebSQL to IndexedDB


I am currently working on a mobile application for time card submission that works with an already existing accounting application. Needless to say, this application relies heavily on relational databases and that particular reliance translates to the mobile app.

In it's current state, the mobile application uses WebSQL for offline access of tables that are loaded onto the device while the user has internet access. Time Cards are created on the local database and then later uploaded when the user regains internet access. This functionality is the core of the application.

My question is whether a transition to IndexedDB is A.) Feasible and B.) A smart move. Had WebSQL avoided deprecation, this wouldn't be an issue. I am beginning to understand IndexedDB better and how JSON can make it useful for relatively complex data storage, but I can't really wrap my head around whether it can actually replicate the functionality of a relational database.

Based off the requirements of the application, it appears that IndexedDB is not an alternative, but I'm still very new to the concept and open to enlightenment.

So can IndexedDB potentially be an alternative? Can IndexedDB be used to replicate the functionality of a database with multiple related tables with large amounts of data. If so, where can I find information on how to do it. If not, do I have an alternative to the two? (Assuming WebSQL does, in fact, lose support and IndexedDB isn't viable).

On a related note, would IndexedDB speed up the population of the local database? PHP is currently used to populate the database while the user is online and it does take a decent amount of time to fill of table with a hundred or so options. When it gets near a thousand, the application just flat out breaks down (This is an uncommon occurance and the clients are strongly discouraged from using that much data).

Any help on this would be great, I'm very new to programming in general and VERY new to web development.


Solution

  • According to http://www.caniuse.com/indexeddb , the support for indexedDB is rather limited, so I wouldn't jump to it for now. But that will most likely change in the future, when the implementations mature.

    Personally, IndexedDB looks strange and complicated, especially when you go beyond simple single-table operations. I have not run any actual tests on it, but since you have to do some things (like join records) manually, you will end up with quite a lot more JS code, which translates to more area for bugs to hide.

    So can IndexedDB potentially be an alternative? Can IndexedDB be used to replicate the functionality of a database with multiple related tables with large amounts of data. If so, where can I find information on how to do it. If not, do I have an alternative to the two? (Assuming WebSQL does, in fact, lose support and IndexedDB isn't viable).

    A quick search brings up http://blog.oharagroup.net/post/16394604653/a-performance-comparison-websql-vs-indexeddb , which shows some patterns for IndexedDB multiple table usage. It also shows some performance comparison, which looks promising for IndexedDB. However, see this answer and take this benchmark with a grain of salt.

    On a related note, would IndexedDB speed up the population of the local database? PHP is currently used to populate the database while the user is online and it does take a decent amount of time to fill of table with a hundred or so options. When it gets near a thousand, the application just flat out breaks down (This is an uncommon occurance and the clients are strongly discouraged from using that much data).

    I am a developer of a similar app for a different industry, and my experience is quite different: even on an older iPhone 3GS, the WebSQL solution runs adequately - we have tested schemas with several thousand records per table with no significant slowdowns. Are you maybe inserting each row in a separate transaction?

    Most of our clients are satisfied with the app since it runs on iPads, iPhones, Android tablets and Google Chrome. But one client's security requirements only permit usage of Windows and IE, no alternative browsers or non-Windows mobile devices. That is the only scenario we've seen where WebSQL doesn't cut it. We looked into IndexedDB and native apps, and so far we consider native apps a better option (C# base library could be shared between Xamarin and Windows Phone apps, not to mention C# would be so much more pleasant to code than loose-typed JS callback hell).