Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are my data saved in WebSQL and not in IndexedDB? (ionic)

I can't understand this simply thing. I need to store data in a database so, following the ionic documentation, I did exactly what this page says:

https://ionicframework.com/docs/storage/

I read on web that WebSQL is deprecated so I'd like to use IndexedDB to store data. The problem is that using get/set methods and running "ionic serve" I see that data is stored in WebSQL (in the form of a string, so difficult to see objects like in IndexedDB).

What am I doing wrong? How to store in IndexedDB and why prefer it to WebSQL?

like image 609
AlessioF Avatar asked Apr 16 '18 17:04

AlessioF


People also ask

What is IndexedDB and WebSQL?

IndexedDB used to have a competing spec called WebSQL Database, but it was deprecated by the W3C. While both IndexedDB and WebSQL are solutions for storage, they do not offer the same functionalities. WebSQL Database is a relational database access system, whereas IndexedDB is an indexed table system.

How many types of Storage are available in ionic framework?

Today we will explore the differences between Ionic Storage, Capacitor Storage, plain SQLite storage, and Ionic's Secure Storage solution.


2 Answers

From the Docs

Configuring Storage

The Storage engine can be configured both with specific storage engine priorities, or custom configuration options to pass to localForage. See the localForage config docs for possible options: https://github.com/localForage/localForage#configuration

You have to pass the order correctly.

IonicStorageModule.forRoot({
  name: '__mydb',
     driverOrder: ['indexeddb', 'sqlite', 'websql']
})

if so delete sqlite and websql and try again

like image 85
fastr.de Avatar answered Sep 23 '22 08:09

fastr.de


it is really easy just : add ‘localstorage’ to driverOrder like this::

IonicStorageModule.forRoot({
  name: “Database”,
  driverOrder: [“indexeddb”, “localstorage”]
}),
like image 30
ali talaee Avatar answered Sep 20 '22 08:09

ali talaee