ionic-team / ionic-team/ionic-storage
Error: No available storage method found when using CordovaSQLiteDriver with Ionic Storage
- Dominant language
- TypeScript
- Stars
- 456
- Forks
- 97
- PR merge metrics
- No merged PRs in 30d
Description
Hi, I want to move from IndexedDB to SQLite and I am currently trying out the SQLite installation instructions.
I've created a StorageService that specifies a custom driver implementation and I am trying to run my Ionic application in the browser.
When I include Drivers.IndexedDB in the driverOrder list even though CordovaSQLiteDriver is placed first and defined, Ionic Storage defaults to IndexedD and ignores CordovaSQLiteDriver.
When I comment out IndexedDB, the following exception is raised:
```
Error: Uncaught (in promise): Error: No available storage method found.
Error: No available storage method found.
at vendor.js:31073:25 [angular]
at Object.onInvoke (core.mjs:26108:33) [angular]
at polyfills.js:9046:28 [angular]
at vendor.js:74280:49 [angular]
at AsyncStackTaggingZoneSpec.onInvokeTask (core.mjs:25794:36) [angular]
at Object.onInvokeTask (core.mjs:26095:33) [angular]
at drainMicroTaskQueue (zone.js:581:35) []
at resolvePromise (zone.js:1193:31) [angular]
at polyfills.js:8895:9 [angular]
at polyfills.js:8911:25 [angular]
at asyncGeneratorStep (asyncToGenerator.js:6:1) [angular]
at _throw (asyncToGenerator.js:25:1) [angular]
at Object.onInvoke (core.mjs:26108:33) [angular]
at polyfills.js:9046:28 [angular]
at vendor.js:74280:49 [angular]
at AsyncStackTaggingZoneSpec.onInvokeTask (core.mjs:25794:36) [angular]
```
The same issue happens when I am testing in an iOS simulator.
Would really appreciate any advice on how to resolve this issue or if I am missing out on something.
Am I supposed to instantiate SQLite somewhere else first?
Here are the files that I am using:
**app.module.ts**
```
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
HttpClientModule,
IonicModule.forRoot(),
IonicStorageModule.forRoot({
driverOrder: [
CordovaSQLiteDriver._driver,
// Drivers.IndexedDB
]
}),
AppRoutingModule,
DirectivesModule,
],
providers: [
StatusBar,
BackgroundMode,
DatePicker,
SocialSharing,
Clipboard,
LocalNotifications,
GoogleAnalytics,
File,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
{ provide: ErrorHandler, useClass: GlobalErrorHandlerService },
],
bootstrap: [AppComponent]
})
export class AppModule { }
```
**storage.service.ts**
```
import { Injectable } from '@angular/core';
import { Storage, Drivers } from '@ionic/storage';
import CordovaSQLiteDriver from 'localforage-cordovasqlitedriver'
@Injectable({
providedIn: 'root'
})
export class StorageService {
private _storage: Storage | null = null;
constructor() { }
async init(): Promise {
await this.storage.defineDriver(CordovaSQLiteDriver);
console.log(this.storage.driver); // null
this._storage = await this.storage.create();
console.info(`STORAGE DRIVER : ${storage.driver}`);
}
public get(key: string): Promise {
return this._storage.get(key);
}
public set(key: string, value: any): Promise {
return this._storage.set(key, value);
}
public getStorage(): Storage {
return this._storage;
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.