Store data to SQLite in AngularJS PhoneGap

When you work with a phonegap application, sometimes you need develop a work-offline mode for your app. In this case, SQLite is  a good choice. You can use SQLite to store data you loaded from server-side. If your device lost internet connection, application will load data from SQLite firstly.

Store data to SQLite in AngularJS PhoneGap

Common sense is not a gift, It’s a punishment. Because you have to deal with everyone who doesn’t have it.

To implement, you need install SQLite phonegap plugin for your app. And then, you write a service to handle get/set/remove data in SQLite. And now, I will show you a script that run in my app that uses angularjs, coffee script.

The below is coffee script that implement a factory to get/set/remove cache to SQLite

And DbCache factory should be injected to factories used to load data.  The below is my way:

– Load from SQLite cache firstly

– If Cache is empty,  use $http to load data from server-side

Code example:

 

  • Eduardo Miranda Soares

    Can you show some example of this factory in action?

    • thanhson1085

      Updated. I hope It is what you needed.

  • Anh Nguyen

    Do you have pure javascript version? I prefer pure one to coffee script 🙂

  • Pingback: Mobile Dev - gustelle | Pearltrees()

  • steelcitydeveloper

    unexpected if statement in your 2nd coding file.