ionic-team / ionic-team/ionic-storage
Storage and SQLitePlugin .create() Lifecycle on Angular apps
- Dominant language
- TypeScript
- Stars
- 456
- Forks
- 97
- PR merge metrics
- No merged PRs in 30d
Description
Hi! I'm working on an Angular app which will be built with Cordova in Desktop and mobile devices.
I'm using:
* `"@ionic/storage-angular": "3.0.6"`
* `"localforage-cordovasqlitedriver": "1.8.0"`
* `"cordova-sqlite-storage": "6.0.0"`
* Angular: 13.2.6
* Ionic Framework: @ionic/angular 6.0.14
I've defined the IonicStorageModule definition as mentioned on the docs:
```typescript
IonicStorageModule.forRoot({
driverOrder: [CordovaSQLiteDriver._driver, Drivers.IndexedDB, Drivers.LocalStorage],
})
```
And I have a service where I manage the storage creation (`.create()`) and the `get()`, `set()`, etc for the Storage.
```typescript
private readonly storageReady = new BehaviorSubject(false);
constructor(private readonly storage: Storage) {
this.init();
}
async init(): Promise {
await this.storage.defineDriver(CordovaSQLiteDriver);
await this.storage.create();
this.storageReady.next(true);
}
get(valueKey: string): Observable {
return this.storageReady.pipe(
filter(ready => ready),
switchMap(() => {
return from(this.storage.get(valueKey));
})
);
}
```
My doubt is:
While developing (serving the app) or building with Angular, the storage creation (`await this.storage.create();`) is awaiting to be created so I can get data from it on App initialization.
But when building for browser (`cordova build browser`) the SQLitePlugin is used and the database is ready to use after the app is completely loaded. The `this.storageReady.next(true);` is executed and then the following is printed on the console in Developers tools:
```
Angular is running in development mode. Call enableProdMode() to enable production mode.
bootstrap.js:12 Ionic Native: deviceready event fired after 207 ms
SQLitePlugin.js:174 OPEN database: _ionicstorage
SQLitePlugin.js:105 new transaction is queued, waiting for open operation to finish
SQLitePlugin.js:178 OPEN database: _ionicstorage - OK
SQLitePlugin.js:79 DB opened: _ionicstorage
```
So, Is there any way to be able to truly wait for the SQLite DB creation so it can be accessible? Or if is better to use other approach?
Contributor guide
Assessment
This issue has not been assessed yet.