Question about storage engine and SQLite

Hi,

I am building an app that runs on iOS and Android natively (no web version) and I have some questions related to the storage engines in Ionic especially SQLite.

On the Ionic Storage documentation page, there is this line:

When running in a native app context, Storage will prioritize using SQLite, as it’s one of the most stable and widely used file-based databases…
…and followed by a short tutorial on how to install SQLite.

To give some background about my app, I am currently using the Ionic storage API in its standard form via methods like this.storage.get(), this.storage.set() and this.storage.clear(). The app is saving data properly without any issues.

What I would like to know is, with that statement in the documentation, did it mean Ionic is already using SQLite by default to store data when the app runs natively on iOS & Android? How can I confirm what storage engine is being used in the native environment?

Or is SQLite something that we have to install and configure ourselves beforehand to make this storage engine available for Ionic to use?

Perhaps a follow-up question, is Ionic Storage by default already supports SQLite to store data in native app context but the only reason to install the cordova-sqlite-storage plugin is for developers to use SQL-like syntax when working with their data?

Thank you.

Yes, that’s correct. SQLite is used first on Android and iOS.

Yes, you have to install it. Further down in the Usage details, it mentions this:

First, if you’d like to use SQLite, install the cordova-sqlite-storage plugin:

ionic cordova plugin add cordova-sqlite-storage

Add the Cordova plugin then you’ll be set.

Hi @netkow

My project is using Capacitor so I followed the Capacitor installations steps, then tested the app with only a single storage engine just to be sure and everything seems to be working properly on Android and iOS.

Thank you for your answer.

So to summarize, to make Ionic use SQLite on native app context we have to install the cordova-sqlite-storage plugin and no other code changes is needed in terms of working with the default Ionic Storage API. However, if we want to we also have access to the SQL-like syntax for working with data.

1 Like

Yes, with one difference: Ionic Storage doesn’t provide SQL-like syntax. Its goal is to provide the simplest API that works cross-platform. However, if you wanted that, I’m not positive but I believe you could follow the instructions from cordova-sqlite .