Hello, I am making an IONIC Application, and I am using also Ruby on Rails for the backend API.
I have a question about the data updates on the application from the backend.
So my app has some records (currently saved in app with Cordova SQLite) and i want to show to user
when the app is offline, but when he goes online I want somehow to update those record’s from the backend API
if there is any new change, and save it back to Cordova SQLite database.
My Questions is
- how can I handle this task if I am getting JSON file from the API? I mean how can I save it directly to the database
- how can I check if effectively if there are any new changes in the API database to update ?
- The Cordova SQLite is a good solution to keep saved permanent data on the ionic application ? or there is any better way?
Sorry for my bad English, but it is not my native language.
Is it only possible to change data trough the client ? If not there is a revision handling required. Take a look at PouchDB.
No, the data can be changed only in the backend API, and can be updated in the client when he is online.
If i get it clearly, you want your app to work offline, and to show the user some data stored in SQLite and when the user comes online the data get update from backend (Server API) if there any changes ?
Yes , exactly! I don’t know if the SQLite from Cordova is the best solution or there any better from this !
I took a look at PouchDB, but I don’t know where I can host it and work with it.
SQLite is not bad choose but it has some limits, for me i’m using LocalForage it support many client-side data storing.
Try to create a key in your API with time of the last edit (Example : lastEdit: time in millisecond) and sotre it in app when you get the data first time and watch the app network state, if it went from offline to online send request to get Data from your API
Example : BackEnd/API/GetData?lastEdit=198562548 and compare the lastEdit Key from App with the one in API, if they’re not the same return the last edited data with lastEdit time and store them in your app.
If you need to check the network state use Ng-cordova network solution.
I’ve got the same issue too. I have a list of records which is being get from database. I wanna update records whenever a new record added.
Have you any suggestion?