ionic2/3 Pre-Populated Database Example
October 29, 2017 ยท View on GitHub
Simple Ionic 2/3 pre-populated database starter project.
To install this project:
- Clone project
git clone https://github.com/iursevla/ionic2-PreDB.git - Inside the project folder run:
npm i - Add android platform:
ionic cordova platform add android - Next:
ionic cordova build android - After that:
ionic cordova run android
Now you should see on your emulator/device the project and on the main page the elements from the database data.db table testTable.
Important Note
I used the emulator for android Google Nexus 5X - 6.0.0 - API 23 from Genymotion
Start from scratch:
- Create ionic project e.g.,
ionic start projectName blank - Add cordova-sqlite-ext:
ionic cordova plugin add cordova-sqlite-ext --save - Create the database (you can use DB Browser for this) and copy the .db file to your project
/wwwfolder. - Add code to your
home.tsfolder to open the pre-populated database and then execute some query on a existing table on said database. - Run your project on a emulator/device and see the results.
Possible problems
-
If you can't execute with sucess the commands:
ionic build androidorionic run androidthen run:cordova platform add https://github.com/apache/cordova-android
Async/Await
This example contains commented code to use async/await to query the database.
To use this code, you should go to home.ts and comment lines 16-23 and uncomment line 24 and the method called accessDB().
Then go to tsconfig.json and change "target":"es5" to "target":"es2015"