1

I have mutiple tables on my server side which I need to fetch data from and store it on my client side Phonegap so it can be accessed offline.

I found Lawnchair but I can't find enough documentation how to save and update mutiple tables.

There is also WebSQL but I believe it's deprecated. (Please correct me if I'm wrong)

How can new data get fetched/ current data gets updated only when the device gets connected online?! In other words, any operation will be done on the data saved on the device.

omarsafwany
  • 3,695
  • 8
  • 44
  • 75
  • Cordova database plugin? [link](https://cordova.apache.org/docs/en/3.0.0/cordova_storage_storage.md.html) – quilkin Jul 26 '15 at 17:53

2 Answers2

1

There are a couple SQLite plugins, I've used the one from Brodysoft with success: https://github.com/litehelpers/Cordova-sqlite-storage

There are no events for when a device goes online/offline. There's a plugin for network connectivity events (cordova-plugin-network-information). You can also sync when the app launches, or have a "sync now" button/gesture so the user can sync on demand.

Dave Wolfe
  • 660
  • 5
  • 14
0

You can use pouchdb:

PouchDB is an open-source JavaScript database inspired by Apache CouchDB that is designed to run well within the browser.

The documentation there is really good and it works pretty well.

You can use it to replicate/sync (bidirectional) your local database with a remote one.

You can always disable the replication and managed it yourself.

It can be used with different adapters:

  • LocalStorage
  • IndexedDB
  • WebSQL

It can be used with SQLite plugin for Cordova/PhoneGap.

Nic Raboy created a really nice video tutorial about pouchdb on his youtube channel.

If you want to activate a manual sync when your app goes online you can use the cordova-plugin-network-information:

cordova plugin add cordova-plugin-network-information

together with $cordovaNetwork plugin from ngCordova.
You could simply intercept the online event:

$rootScope.$on('$cordovaNetwork:online', function(event, networkState){

});

and take actions.

LeftyX
  • 35,328
  • 21
  • 132
  • 193