Mobile Database


Hi, I am working on n Ionic app that uses localstorage for offline data store.

There are about 30 templates in this app. Also any number of users can be added. Local storage is used to store 3 things mostly. First the primary information about users and last signed in user. Second latest notifications of the users to show on app start. Then user can refresh them from server. And also the Chats of the user .

My problem is that recently there was memory crash issue on iOS 8 both on iphone and ipad. In process to track down the problem’s cause I disabled the local storage , then the memory warning didn’t appear. So i am assuming local storage may be the cause of the problem. Also I think size of localstorage is not an issue. I used this code
unescape(encodeURIComponent(JSON.stringify(localStorage))).length); to find the size of local storage. It never goes beyond 2.5MB. The major problem maybe the excessive manipulation on the localstorage data.

My query is should I use SQL Lite for this purpose. If yes what are the best practices to use with cordova app. Would the use of SQL lite can cause more computional overhead ??

P.S. I have also considered using javascript wrappers for localstorage management ( [localstorageDB][1]) but i think internally they also process the same way just providing an abstraction. Also we have same app on android but there is no memory problems on android.

Please provide your suggestions.

Indexed DB vs localStorage

i prefer only to store really necessary data to the localstorage, like information about the user of the app (like api tokens and so on).

But all other stuff can be taken from the database. If you care about app-start -> hide your splashscreen only, if you have the needed data like users info, last messages and so on.

Stuff like chat protocols has nothing to do in the localstorage, because you can not measure them exactly.
For that you could use an internal database (to provide things like offline messages and so on).



Can u suggest any best practices for the database usage. Currently our app hugely rely on local storage. User first logs in and gets some data from server ( eg. list of latest activities relevant to user) and they are stored in local storage. There is a view to show this data and every time user navigates to this view this data is pulled from localstorage. If I use database to store this data then every time there will be a database hit. Wouldn’t it increase the computation ??

Thanks in advance.


@saurabhgupta050 I recommend you to take a look at this post. You might find some answers to your questions.


Thanks … All suggestions in the posts are helpful and by it seems that sqlite is the best option. I only have one doubt regarding SQL. If I use the SQL database the same way I use localstorage , every time a relevant view is loaded the data is pulled from database will it increase the overhead as database calls will be made every time that view is loaded.


In one of my apps I have used sqlite as a pouchdb adapter and its performance was good. But considering your requirements; you can use pouchdb alone or angular-localForage, both will choose either IndexedDB or websql according to availability.


Can you give me a working source code of such an sample application. Also are there any suggestions regarding performance test such apps.

Thanks in advance !!


But something you could do: storing things like userdata you get everytime you enter the view from db and store them in localstorage -> you could have many useless storage writings.

You could store them only in a angular-service so they are storing in the ram of the device and can be used from each controller in your app. It is faster and better.

Anotherthing -> you could add an endpoint of your api to get informed if there are any changes of the user data -> so you only get the changes instead of the the whole data. (you could add timestamps to the db changes and the app has a timeflag of last update -> and so you could get only new or changed stuff. if nothing changed you do not need to update them.


Try Pouch DB ( . Its a no-sql db and works great. I use local storage only for storing 2-3 items like current username, current customer etc. All data that needs to be persisted is in Pouch DB. It works perfectly with Android and iOS too. Since its no-sql, you can directly store JSON data and retrieve it as it is. It also supports stuff like undo. We were using SQLite on our earlier version of app but whenever we changed schema, we would have to do a migration. Such issues dont come up here.


i use with
hope this will help someone :smile:


I personally prefer sqLite for following reasons

  1. its local database
  2. it has support on all major platform

also in Mobile App i use it as a key value store in a single DB, i would store the complete user info as a JSON object and retrieve all the info in one single call.

As there would small query with only key and value in one single table, performance would be fast.