Storage - Preferred Way

Hi All,

I need to implement storage functionality in my Ionic app and a bit confused about which library to use. It’s also because of my lack of my proper knowledge. So just wanted to check with you guys on the preferred way of implementing this in the industry.

I have come across SQLite, LocalStorage or App Preferences. But not sure what I should use.
I did read in some forum that if we install SQLite and code our app using ionic-storage, it will internally use the installed SQLite. Is it true and is it recommended?

Would appreciate if you could please give some insights.

Thanks.

Add Ionic Storage to that list.
Also group these by type:

  • SQLite is relational
  • Local Storage, App Preferences and Ionic Storage are key-value.

Yes, SQLite can be a a backend of Ionic Storage (as a key-value store).

I can’t think of a single situation in which localStorage is the best choice. It is not guaranteed to persist at all, so anything you would be tempted to put in it should either go somewhere that is or just in a transient service provider.

1 Like

So what is the most popular way?

In that case, do you think it’s the best way to go about it? And if I do it this way, I can use the SQLite as key-value store by using ionic-storage or directly as a relational DB. Right?

Right, read that abotu localStorage. The OS can wipe it out.

It is well integrated and works pretty good.
If it is the right one for your depends on your other requirements… if it is just about a login token: Yes.

Yes, add Ionic Native SQLite into the mix and you can also use the relational part. But there will be no connection between the two areas, for the app these are two totally different interfaces. Just in the background it’s the same data store.

Perfect! Thanks for the quick reply, appreciated!!

Will go with SQLite and ionic-storage.

(Note local testing will use no SQLite, but that’s actually just fine)

So there are two version of SQLite:

  • cordova-sqlite-storage
  • ionic-native/sqlite

cordova-sqlite-storage - used as a regular storage engine. Similar to local storage but more persistent as it’s file based.

ionic-native/sqlite - used as a relational db

Thanks!

No.

No. This is a Cordova plugin that enables Cordova apps to use the native SQLite database.

This is a wrapper around the former one to make the code usable in a good way in Ionic.

@ionic/storage

is a key value store, that can optionally use cordova-sqlite-storage as a data store.

1 Like

Oh okay. Got it. I think. :slight_smile:

Thank you, I really appreciate your kind help!