SQLITE Tutorial

hi can anyone give me a working example of sqlite plugin for ionic app. I have the tutorial from the official site but not very helpful. How do I see the results of the queries. Also is there any way to see the schema of the database of the application. I want to see the full schema of the database created so that I can verify it has been created correctly.

Hi friend,

I do believe this will help you, because it helped me as well…

Ionic / AngularJS service wrapper for Web SQL API / SQLite-Cordova-Plugin

1 Like

Yes i have read this. but i am having trouble in verifying the database I have created. I tried the query

db.transaction(function(tx) { tx.executeSql( "SELECT name FROM sqlite_master WHERE type='table'",[], function(res) { console.log("PRAGMA res: " + JSON.stringify(res)); },function(error) { console.log(error); }); });

to print table names. But it returns result {"db":{"openargs":{"name":"sample_db"},"dbname":"sample_db"},"txlock":true,"readOnly":false,"executes":[]}

Is there a way to test if the database created successfully.

Have you seen in services.js a line logging table creation? I used that to verify in my debugging (in chrome and in device)

Hi @saurabhgupta050,

Have you seen the SQLite tutorial I made not too long ago?:

Let me know if this helps you out.


Hi @nicraboy I follow your tutorial and its awesome. But I have a problem when I try to customize it, please take a look at my code:


var db = null;

angular.module('starter', ['ionic', 'ngCordova'])

.run(function($ionicPlatform, $cordovaSQLite) {
  $ionicPlatform.ready(function() {

    if(window.cordova && window.cordova.plugins.Keyboard) {
    if(window.StatusBar) {

    db = $cordovaSQLite.openDB({ name: "my.db" });

    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXIST people (id integer primary key, firstname text, lastname text)");

.controller('AccountController', function($scope, $cordovaSQLite) {

  $scope.accounts = function() {
    var query = "SELECT firstname, lastname FROM people";
    $cordovaSQLite.execute(db, query);

  $scope.addAccount = function(){
    var query = "INSERT INTO people (firstname, lastname) VALUES (?, ?)";
    $cordovaSQLite.execute(db, query, [$scope.firstnameText, $scope.lastnameText]);
    $scope.firstnameText = '';
    $scope.lastnameText = '';



<!DOCTYPE html>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="js/ng-cordova.js"></script>
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>
  <body ng-app="starter">


      <ion-header-bar class="bar-stable">
        <h1 class="title">Ionic Crud & SQLite</h1>

      <ion-content ng-controller="AccountController">

          <form ng-submit="addAccount()">
            <div class="list">
              <label class="item item-input item-stacked-label">
                <span class="input-label">First Name</span>
                <input type="text" placeholder="John" ng-model="firstnameText">
              <label class="item item-input item-stacked-label">
                <span class="input-label">Last Name</span>
                <input type="text" placeholder="Suhr" ng-model="lastnameText">
              <div class="padding">
                <button class="button button-block button-positive">Create Account</button>

          <ul class="list list-inset">
            <li class="item item-divider">
              {{accounts.length}} records
            <li class="item" ng-repeat="account in accounts">
              <i class="icon ion-person"></i>&nbsp; - &nbsp;
              <span>{{account.firstname}} {{account.lastname}}</span>



can you provide us implementation with form and table?

Wild guess, I’m also noob lol. I think it should be “EXISTS” instead of “EXIST”?


Hi All,
Can you please any one having experience in sqlite database synchronization with sql server 2012. If yes please post how to achieve the synchronization.

ie mobile sqlite db to server database & server database sqlite DB. two way synchronization need.
Please help me.

Email : gobimca2012@gmail.com

visit here to get details about how to use sqlite in ionic

I’ve compiled a comprehensive tutorial go through it. It will help you

Hi I was able to do synchronization between SQLite and MySQL on a remote server with PHP as webservice. Check it out here: https://sellfy.com/p/gUWH/
This full app template was built with Ionic 3.6.0 version

I also need one example for that plugin