Here’s my tutorial on making your sqlite work in your ionic application.
1.run “cordova plugin add io.litehelpers.cordova.sqlite”
2.create a file called “yourdb.db” in your www folder.
3.Run “ionic run android —device” to open your app even if its not complete.
4.Open chrome to “chrome://inspect/#devices” and open the developer tool.
5.In order to add the tables you need to sqlite, you must do it on the device. You can’t do it from an editor on your computer from my experience.
6.Type following to your developer tool.
1 | var db = window.sqlitePlugin.openDatabase({name: "yourdb.db", createFromLocation: 1, location: 2, androidLockWorkaround: 1}); |
The first line opens the database. Make sure you have all those options there to enable it to work on both android and ios.
Next create the tables you need.
To see the columns you have run the third line.
Now everything is setup, I’ll show you how to code from ionic.
I have given a non trival example sql module you can use.
I show you how to insert, delete, query, update your database.
app.js
1 | angular.module('home', []) |
sqlService.js
1 | angular.module('sqlService', []) |