Ionic3 / ionic native/ storage / sqlite


#1

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??


#2

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

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.


#4

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.


#5

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: