In my current application I am using @ionic/storage to persist key user data on the device. My specific problem is that during initialisation, Storage appears to wipe the Web SQL database.
I’ve verified myself that Storage
- Writes data.
- Reads data.
Everything in this regard is correct. However, it wipes the store during init. This is what I see after teardown and reload:
The ID key increments on each reload.
Software Versions:
-
@ionic/storage v2.2.0
-
@ionic/native v5.0.0
-
@ionic/angular v4.0.0
Putting aside code to call get/set, our configuration and initialization code is minimal. After we load the storage module we instantiate the service in a wrapper to return observables for ease of use with NGRX.
@NgModule({
declarations: [
AppComponent
],
imports: [
AppErrorsModule,
AppRoutingModule,
AppStoreModule,
BrowserAnimationsModule,
BrowserModule,
HttpClientModule,
InterceptorsModule,
IonicModule.forRoot(),
IonicStorageModule.forRoot(),
MenuModule
],
bootstrap: [
AppComponent
],
providers: [
SplashScreen,
StatusBar
]
})
export class AppModule {}
import { Inject, Injectable } from '@angular/core';
import { Storage } from '@ionic/storage';
import { Observable, from } from 'rxjs';
import { Platform } from '@ionic/angular';
@Injectable({ providedIn: 'root' })
export class StorageService {
constructor(private storage: Storage) {}
get(key: string): Observable<any> {
return from(this.storage.get(key));
}
set(key: string, value: any): Observable<any> {
return from(this.storage.set(key, value));
}
remove(key: string): Observable<any> {
return from(this.storage.remove(key));
}
clear(): Observable<any> {
return from(this.storage.clear());
}
keys(): Observable<Array<string>> {
return from(this.storage.keys());
}
}