Data lost when using ionic/storage

I’m using import { Storage } from '@ionic/storage'; to make iOS app.

Some users report their data is lost after a few days of using. This means for the first few days it saved correctly, but after a few days things went wrong.

I cannot reproduce it on my iPhone. I wonder if the data may be lost in some cases? Like when iPhone storage is not enough and deleted it somehow?

Hey, I guess it is because internal browser storage could be cleared after app is closed or after some cleaning.
If you want to preserve your data use sqlite. Here is more information:

By “use sqlite” all that is really meant is adding the sqlite plugin as described here. You don’t have to change your app code one bit.

Thanks! Does that mean all I need to do is ionic cordova plugin add cordova-sqlite-storage, and do not need to change any code?

Precisely. Bla bla bla Discourse character limits are irritating.

Another question is, if I change the driver from localStorage SQLite, will I lost the previous data with localStorage? Cause my app is already online and many users are using it.

Yes. You will have to come up with some sort of migration strategy for deployed users.

Thank you so much!:heart_eyes:

Sorry, I had to ask for help again…
If I set driverOrder: ['sqlite'] in app.module.ts, SQLite is used by default, how can I migrate previous local storage?

Any idea how to migrate data from local storage?

Hello,
I have never done this before, but my try would:
check if sqlite is used. See here How to check if SQLite actually being used for Storage
Read all datas, change config as described in docu, store it again in new storage.

Best regards, anna-liebt

Ionic storage is a wrapper

Look for ways to access localstorage (the one u use) using plain vanilla js of any other non-ionic api and then use this to fill the ionic storage with a sql engine

May be eadier then trying to switch engines and store all data in menory inthe mean time

Hey @rapropos - do you know that if in a scenario where you have an app in production without the SQLite plugin, then need to add SQLite down the road (say, as a prerequisite for a plugin) will users lose access to the data they’ve already stored?