How to use SQLite in ionic2?

I use the offical example in my project and run with ios emulator ,unfortunately ,something go wrong like that : ReferenceError: Can’t find variable: sqlitePlugin
My code like that ionic 2 sqlite
Any answer I will be appreciate !! :slight_smile:

you can try this, It worked for me

Hi,

Or uses Ionic components : http://ionicframework.com/docs/v2/2.0.0-beta.10/api/platform/storage/SqlStorage/

1 Like

Thank you @piyukore !!!
I used it and worked for me ,but I want to know where the data is stored .
I debuged in my computer with IOS emulator and safari web inspector , but I didn’t find my data in the browser storage space and anywhere ?

Thank you @LAFONT
It’s very helpful !:slight_smile:

@RocWang You are welcome!
I don’t know about that yet. Tell you if I find anything :+1:

OK,thx anyway !:smile:

i tried above link but i get error - supplied parameter do not match any signature of call. On below line i got error

let db = new SQLite();

if i write 'let db = new SQLite(‘dbname.db’);'
then above error gone and get new error that is - Property openDatabase does not exist on type SQLite.

why this all happened??

Hi , @varshil29 I didnt write like that .
Instead , U can try this :

//init database
let storage = new Storage(SqlStorage, {name: ‘mydb’});

//init table
storage.query(‘CREATE TABLE IF NOT EXISTS t_user (id INTEGER PRIMARY KEY AUTOINCREMENT,USERNAME TEXT’).then((data) => {
console.log("TABLE CREATED -> " + JSON.stringify(data));
}, (error) => {
console.log("ERROR -> " + JSON.stringify(error.err));
});

//exec query
let sql = ‘select id,username from t_user’;
storage.query(sql).then(res=>{
// TODO
})

And U should do this:
import {Storage, SqlStorage} from “ionic-angular/index”;

I already used this code but i got problem in android device.
i open topic in forum. please refer link

Thank you

please refer below link

having same problem.
"- supplied parameter do not match any signature of call. "
in this line —let db = new SQLite();

I found an greate solution
The oficial documentation example doesnt works for me!

Maybe this can help someone - https://gist.github.com/aggarwalankush/0b700328e797e22a1d9994cb35afdf09