Ionic Sqlite


#1

Hello,
currently i am learning ionic2 to develop a simple android app which can store data locally using sqlite.

I followed some tutorials and i keep getting error on this line of code which is:

home.ts

import { Component } from ‘@angular/core’;
import { NavController } from ‘ionic-angular’;
import { SQLite } from ‘ionic-native’; ->> Cannot find module ‘ionic-native’
@Component({
selector: ‘page-home’,
templateUrl: ‘home.html’
})
export class HomePage {

constructor(public navCtrl: NavController) {

}

}

Can some one point out where is my mistake?
I have executed following commands after this project has been created:

  1. cordova platform add android
  2. ionic cordova plugin add cordova-sqlite-storage

Thanks…


#2

@Ressa_Panda hi, the mistake is ionic does not use sql lite by default (you touch the good idea, but don’t call it the right way). Most modern browsers, like Chrome or Firefox use sql lite all the time, even if you don’t call it.

The other issue is to call it from within a ionic app. Most people like me, don’t do it (call the browsers sql lite local storage) because it involves that at next restart of the browser, this sql lite database will be flushed.

So to avoid this issue, I use simple scripts. And ideas. And techniques.

Hope it helps,


#3

Sounds like you’re looking at old tutorials.

The new place to import from is “@ionic-native/sqlite”. (If I remember correctly)

If your data model isn’t terribly complicated I’d recommend looking into Ionic Storage first though, as it’s easier to use.


#4

@SigmundFroyd
Thanks for the kind reply and suggestion,

Do you know where i can find newest and updated Ionic2 SQLite tutorial?

My data needs to be synced to an online database and in term of size my data is small, but amount, it can be quite many of them. Using Ionic Storage might not be a proper solution even though it’s possible


#5

@FrancoisIonic
Thank you for the reply,

It seems like this tutorial i am referring to is outdated, do you know where i can find the updated one?