Hello there, we have an already productive Capacitor Ionic App.
We, unfortunately, don’t included the plugin cordova-plugin-sqlite
so the user currently stored the data inside indexeddb
, websql
or localstorage
as we just use the default config of ionic/storage
.
We have a few storage problems on android devices with android 8, which is why we wanted to include the sqlite plugin. The problem now is, that the users data is lost because the data is stored with another driver.
Does anyone know how to migrate the data from one of the other technologies to sqlite?
Thank you very much!
Edit: As suggested the solution is to directly use the localforage to have a look what data is stored. This is the code that helped me:
import { Storage } from "@ionic/storage";
import * as localforage from "localforage";
...
constructor(private ionicStorage: Storage) {
this.storage = ionicStorage;
localforage.config({
name: "_ionicstorage",
storeName: "_ionickv",
driver: [
localforage.INDEXEDDB,
localforage.WEBSQL,
localforage.LOCALSTORAGE,
],
});
}
public async get(key: string): Promise<string> {
let result: string | null = null;
try {
result = await this.storage.get(key);
} catch (error) {
result = null;
}
if (!!result) {
this.logger.warn("Found data in ionic/storage for ", key);
return result;
}
this.logger.warn("Found no data in ionic/storage for ", key);
try {
const dataFromForage = await localforage.getItem<string>(key);
if (!!dataFromForage) {
this.logger.info("Found data in forage for ", key);
await this.set(key, dataFromForage);
return dataFromForage;
}
} catch (error) {
this.logger.error("Received error on checking localforage", error);
}
this.logger.warn("Found no data at all anywhere");
return null;
}
...