Capacitor, SQL Database, and offline data mode questions

New to the tech stack and wondering how easy it is to support an offline mode with Capacitor? Planning on using the full VUE stack (including Axios js). Completely fine with using SQLLite locally. We are using SQLServer and MariaDB for backends. My experience is that you can find modules that do what you want but they don’t necessarily work together. So is there a clean pipeline of modules that will get me from point A to Z or am I going to have to program a whole bunch of stuff to make this work?

For most cases with offline support, all you need to do is check if your API is reachable or not. All of the web assets are included in the application bundle and the SQLite is on the device if you need it. You can use @capacitor/storage to store non-relational data and @ionic/storage if you need the data to be stored in an SQLite database.

Not sure how your app is set up, but I’d assume it looks something like this:

  • Your application reads data in from @ionic/storage. This data is stored locally on your device.
  • Your application gets new data by calling axios.get("") and stores the response data in @ionic/storage.
  • If the API call for getting the new data is successful, re-render your UI with the updated data. Otherwise, keep showing the old data and optionally show a small pop-up saying there was an error getting the updated data.

How would you keep track of what hasn’t made it back to the main DB Server? DateTimeStamp, Flag, other? This will be a work order system that gets updated in the field and they may or may not have connectivity back to the main DB server.

And thanks for the response.

My answer is “don’t”, because there isn’t enough information on the client side to do that reliably. The backend should be capable of discarding PUTs for stale data. The most the client can do is note internally whether a particular business object initially came from the server (and has not been modified since), and choose not to submit those things, but there will always be edge cases where only the server can know the truth, and it has to be gracious in accepting submissions, but carefully judicious in how it applies them.

1 Like