Ionic prepopulated database with Antair Cordova-SQLitePlugin [help request]


____ INTRO

Hello everyone, first of all, three clarifications:

  1. My english is not good, so I beg your pardon in advance for my mistakes,
  2. I’m a newbie so forgive me for inaccuracies,
  3. I have previously searched and tried the solutions I found on the internet but still I can not solve the problem of embedding a prepopulated database.


I want to develop an app for iOS and Android with a prepopulated database.

Just for example, the database consists of 15.000 records each one made of three key-value pair (id, firstname and lastname). I still do not know what is the best solution: JSON or SQLite?
(Could you give me an answer here?)



ionic start myapp blank
cd myapp
ionic platform add ios
ionic platform add android

Then I created an sqlite database for testing purpose, named mydb.sqlite, made of one table people containing two id, firstname, lastname records.

I decided to use the following plugin:
That’s because it can be installed with cordova tool.

ionic plugin add

(Alert: I think that the instructions on the website show an incorrect reference - “cordova plugin add - which refers to another plugin).

Then, following the instructions on the plugin website, I copied the database to myapp/www/db/ so that it can now be found at myapp/www/db/mydb.sqlite

I modified the index.html including the SQLite plugin just after the default app.js script:

<!-- your app's js -->
<script src="js/app.js"></script>
<script src="SQLitePlugin.js"></script>

I also write some lines of code in index.html file to show a button:

<ion-content ng-controller="MyCtrl">
    <button class="button" ng-click="all()">All</button>

Finally I had modified ./js/app.js:

// Ionic Starter App

var db = null;

angular.module('starter', ['ionic' /* What goes here? */ ])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // some predefined code has been omitted

    window.sqlitePlugin.importPrepopulatedDatabase({file: "mydb.sqlite", "importIfExists": true});
    db = window.sqlitePlugin.openDatabase({name: "mydb.sqlite"});

  }); // $ionicPlatform.ready
}) // .run

.controller('MyCtrl', function($scope){

    $scope.all = function(){
            var query = "SELECT * FROM people";
            // I don't know how to proceed
    }; // $scope.all

}); // .controller


I don’t know how to proceed in the controller section to query all the records (just an example of query) and show the results in the console.log.

I think that the following code must be completed in some way:

angular.module('starter', ['ionic' /* What goes here? */ ]) 

And also the code inside controller section must be completed:

       $scope.all = function(){
                var query = "SELECT * FROM people";
                // I don't know how to proceed
        }; // $scope.all


Thank you in advance for the help you will give to me.