ionic-team / ionic-team/ionic-storage

Storage and SQLitePlugin .create() Lifecycle on Angular apps

Aperta
#254 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
456
Fork
97
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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?

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con la sequenza init() del servizio e la configurazione del driver di IonicStorageModule, quindi riproduci la temporizzazione con `cordova build browser` esaminando i messaggi di apertura e transazione di SQLitePlugin.js. Determina quando il database SQLite è effettivamente pronto rispetto a `storage.create()` e `storageReady.next(true)`; il lavoro è completato quando l'inizializzazione espone in modo affidabile lo storage solo dopo che il database è utilizzabile, oppure quando vengono documentati il limite supportato e l'approccio.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
angular, sqlite, typescript
Ambito
databases, mobile-dev
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.