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

2

8

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?

Qintar answered 16/4, 2018 at 17:52 Comment(0)
B
1

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

Beaker answered 16/4, 2018 at 21:0 Comment(5)
The link is about "forage" (and I don't know what it is). In fact if I write that code deleting sqlite and websql, I get the error Error: No available storage method found.Qintar
forage is the StorageEngine that is used by ionicStorage. The Quote is from the page you are linked to ionicframework.com/docs/storage. When you get the above error indexdb is not available so IonicStorage is switching to websql to store the dataBeaker
So is there a way to make IndexedDB available?Qintar
@Qintar Maybe you have already worked it out, but just in case somebody comes across your post and wants to set up an indexed db web app: use Dexie: dexie.org. I can't understand why they made Indexed DB such a nightmare to use, dexie is a very intuituve layer which makes your life much easier. I am aware of other projects which do the same, but I haven't tried them.Parrot
@Qintar There is an issue is in the chrome dev tools. The predefined iPhone sizes in the size selection don't support indexeddb as a storage. In that case Ionic Storage/ localForage is falling back to use websql. Switching between sizes like responsive <> iPhone can also lead to duplicate storage entries, because of the fallback. See also my comment on this answer #50370326 .Schoolfellow
S
1

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

IonicStorageModule.forRoot({
  name: “Database”,
  driverOrder: [“indexeddb”, “localstorage”]
}),
Sorenson answered 11/2, 2020 at 10:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.