Converting from WebSQL to IndexedDB

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

In its current state, the mobile application uses WebSQL to offline access to tables being downloaded to the device while the user has Internet access. Time maps are created in a local database and then loaded when the user regains Internet access. This functionality is the core of the application.

, IndexedDB A.) B.) . WebSQL , . IndexedDB , JSON , , .

, , IndexedDB , .

So could IndexedDB be an alternative? Can IndexedDB be used to replicate database functionality with many related tables with large amounts of data. If so, where can I find information on how to do this. If not, do I have an alternative to the two? (Assuming WebSQL will indeed lose support and IndexedDB is not viable).

As for the related note, will IndexedDB accelerate the local database population? PHP is currently used to populate a database when the user is online and it takes quite a while to populate a table with hundreds or so. When it gets close to the thousands, the app just flattens out (this is an unusual event and customers are strongly discouraged from using that much data).

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

+3


source to share


3 answers


According to http://www.caniuse.com/indexeddb , indexedDB support is pretty limited, so I wouldn't skip right now. But this is likely to change in the future as realizations mature.

Personally, IndexedDB looks odd and complex, especially when you go beyond simple single table operations. I haven't run any real tests, but since you have to do some things (like writing the joins) manually, you end up with a lot more JS code, which translates into more areas for hiding errors.

So could IndexedDB be an alternative? IndexedDB can be used to replicate database functionality with multiple interconnected tables with large amounts of data. If so, where can I find information on how to do this. If not, do I have an alternative to the two? (Assuming WebSQL will indeed lose support and IndexedDB is not viable).

A quick search calls up http://blog.oharagroup.net/post/16394604653/a-performance-comparison-websql-vs-indexeddb which shows some patterns for using multiple IndexedDB tables. It also shows some performance comparisons that look promising for IndexedDB. However see this answer and take this test with a grain of salt.



In a related note, will IndexedDB accelerate the local database population? Currently PHP is used to populate a database while the user is online and to populate a table with a hundred options. When it gets close to a thousand, the application just flat-breaks (This is an unusual event and clients are strongly discouraged from using that much data).

I'm a developer of a similar application for a different industry, and my experience is completely different: even on the earlier iPhone 3GS, the WebSQL solution works adequately - we tested schemas with several thousand records per table without significant slowdowns. Perhaps you are inserting each row in a separate transaction?

Most of our customers are happy with the app as it works on iPads, iPhones, Android tablets and Google Chrome. But one client security requirement only allows the use of Windows and IE, no alternative browsers or non-Windows mobile devices. This is the only scenario we've seen where WebSQL doesn't shortcut it. We've looked into IndexedDB and native apps, and so far, we see native apps as the best option (the core C # library could be shared between Xamarin and Windows Phone apps, not to mention that C # would be much nicer to code than debugged JS callback hell).

+2


source


I am a couple of years late but thought I would drop by and answer the OP's questions (both for his benefit (maybe) and for anyone else who ended up here with the same questions) that have not been directly answered already and also suggest some offers!

Do I have an alternative to the two? (Assuming WebSQL will indeed lose support and IndexedDB are not viable).

IndexedDB is the only database that remains on the W3C standards track at the moment, and as such is pretty much the only option as the original client side databases go.

So could IndexedDB be an alternative? Can IndexedDB be used to replicate database functionality using multiple linked tables with large amounts of data.

Well...

IndexedDB is a non-relational document store .

  • Non-relational: does not allow you to define any relationships between records that exist in its object stores (tables). All such relationships must be defined and maintained by the application.

  • Document storage: storage of documents, which are freely structured data items.

A relational database , on the other hand, supports both defining and maintaining relationships between table elements. Most of these databases are also row stores, which (as you probably know) are repositories of tuples contained in tables that define their respective structures.



So, to answer your question, yes, you can replicate the functionality provided by your relational database to IndexedDB. And if any item of data in the store is related to each other in any way, you have to to some extent.

But given that the client-side database is just a temporary stop for your data, it would be wise to replicate only the bare minimum to maintain the integrity of your data there, and just take advantage of the rest of the functionality as it does in a server-side relational database after data transfer.

If the thought of converting still seems acceptable, go for it!

But before you do that, there are a couple of things you need to know about IndexedDB. The first should be obvious given the type of database: it doesn't support SQL. Secondly, its API ... is inconvenient, to say the least.

With these things in mind, I suggest you check out BakedGoods . In this case, placing one or more data items in the IndexedDB database, for example, is performed in the same way as:

bakedGoods.set({
    data: [{key: "key1", value: "value1"}, {key: "key2", value: "value2"}],
    storageTypes: ["indexedDB"],
    function(byStorageTypeStoredItemRangeDataObj, byStorageTypeErrorObj){}
});

      

Since some relational database functionality may require complex CRUD operations to replicate, you can take advantage of BakedGood's support for custom storage functions .

For the sake of complete transparency, BakedGoods is backed by this guy right here :).

0


source


Typically, it is difficult for SQL developers to use indexeddb due to its complex apis.

The solution is to use any indexedb library that makes indexingb easier, but again, in order to use the library I need to know a little about the indexeddb concept.

JsStore is an indexeddb library that removes the complexity of indexeddb and makes indexeddb easier to use. It provides Sql as an apis making it easy to learn.

Let's say - you have a sql query: select * from table_name where id=1 and name='abc'

In JsStore - the request will be:

var con = new JsStore.Instance(db_name);
con.select({
     From:table_name,
     Where: {
         Id: 1,
         Name:'abc'
     }
}).then(function(result){
   console.log(result)
})

      

0


source







All Articles