title: read data from pre populated database file in ionic
body: <p>I am new to ionic framework. I am reading data from populated database file in ionic.the database file is in json format. In json file my database name, table name and data available. How to read data from this database file using angularjs in ionic</p>
  
  <p>I followed this tutorial:<a href="https://www.thepolyglotdeveloper.com/2015/01/deploy-ionic-framework-app-pre-filled-sqlite-db/" rel="nofollow">https://www.thepolyglotdeveloper.com/2015/01/deploy-ionic-framework-app-pre-filled-sqlite-db/</a></p>
  
  <pre><code>var db;
  angular.module('starter', ['ionic', 'starter.controllers', 'ngCordova'])
      .run(function ($ionicPlatform, $cordovaSQLite) {`enter code here`
          $ionicPlatform.ready(function () {
              if (window.cordova &amp;&amp; window.cordova.plugins.Keyboard) {      
                  cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
                  cordova.plugins.Keyboard.disableScroll(true);
              }
              if (window.StatusBar) {
                  StatusBar.styleDefault();
              }
  
              window.plugins.sqlDB.copy("gr.json", function() {
                  db = $cordovaSQLite.openDB("grocery.db");
                }, function(error) {
                  console.error("There was an error copying the database: " + error);
                  db = $cordovaSQLite.openDB("grocery.db");
              });
  
          });
      })
  </code></pre>
  
  <p>This is my <strong>controller.js</strong></p>
  
  <pre><code>angular.module('starter.controllers', [])
      .controller("ExampleController", function ($scope, $cordovaSQLite) {
          $scope.selectAll = function(){
              var query = "SELECT * FROM grocery1";
              $cordovaSQLite.execute(db, query, []).then(function(res) {
                  if(res.rows.length &gt; 0) {
                      alert("in query");
                      for(var i = 0; i &lt; res.rows.length; i++) {
                      }
                  } else {
                      alert("no response");
                  }
              }, function (err) {
                  alert("Error");
          });
      };
  });
  </code></pre>
  
  <p>This is  my database file <strong>gs.json</strong>, I generated this file using sqlite studio.i added some rows. i want to read these added rows.</p>
  
  <pre><code>{
      "type": "database",
      "name": "grocery",
      "objects": [{
          "type": "table",
          "database": null,
          "name": "grocery1",
          "withoutRowId": true,
          "ddl": "CREATE TABLE grocery1 (name CHAR (20))",
          "columns": [{
              "name": "name",
              "type": "CHAR"
          }],
          "rows": [
              [
                  "sdd"
              ],
              [
                  "adddd"
              ],
              [
                  "add"
              ],
              [
                  "asd"
              ],
              [
                  "aaa"
              ]
          ]
      }]
  }
  </code></pre>
  
  <p>Please help me how to read data from this file. I am getting error alert. The cursor not entering inside execute function. Is there any other way to read data from database file in ionic?</p>