Ionic3 / ionic native/ storage / sqlite

I was playing around with ionic framework for a quite while now, and the massive updates they done so far for the framework are so dam good, but there is a good question regarding the storage system in ionic.

if you create a new project and you dig down to the project structure you will find modules that already referenced by ionic framework from the storage perceptive (localForage, SQLite, and localStorage).

in which they have said in their documentation here that ionic is smart and will choose the preferred type of storage to use when you are in device or browser, and then itā€™s saying that if you would like to use sqlite install the plugin, how come itā€™s already being used in the back scene?, so thatā€™s why i am confused so far with this, and there is also a place in native documentation for SQLite and SQLitePorter, so the real question is when i use this:-

import { Storage } from ā€˜@ionic/storageā€™;

or

this: import { SQLite} from ā€˜ionic-native/sqliteā€™;

what are the differences?

since the itā€™s saying it will auto detect and then it asks you to install the plugin??

1 Like

Ionic Storage is a key value store that is very simple to use in Ionic and that chooses the best option of the available storage options on your platform. When you add SQLite via a native plugin, it will use this as it has clear advantages.

Ionic Native SQLite adds a way to easier use the Cordova SQLite plugin in Ionic, SQLite is not ony a key value store, but a complete database system, so you can write queries etc.

See my explanation, key value store with different backends on different platforms (one optionally being SQLite via Cordova plugin) vs. full database via Cordova plugin. Native Cordova plugins only work on devices, and mostly not on ionic serve or in the browser.

3 Likes

Thanks a lot for the clarification, but still there is something i didnā€™t get:-

IOnic storage != localStroage, itā€™s like a mix of SQLite, IndexedDB, and LocalForage,

but there are two options to deal with SQLite, one is by the Ionic Native, and the other one by cordova native plugin through Ionic storagre, is this a correct explanation?

and which one to use? ionic native /sqlite or ionic storage with cordova plugin for sqlite is installed.

1 Like

No.

If you want to ā€œdeal with SQLiteā€ (which means using the full database tool SQLite with queries and all), use Ionic Native. This is proper SQLite with all its advantages and disadvantages.

If you want to use a key value store (that may be backed by SQLite as an internal storage backend), then use Ionic Storage. Ionic Storage doesnā€™t let you ā€œdeal with SQLiteā€ in any way, it just uses it as one of multiple backends if available.

3 Likes

That is well said, now i come to know the real connection between them, many thanks to you it just make sense now for me :smiley:

1 Like