How to use SQLite in a Cordova application?

2

Gentlemen, I have a hybrid application that I built in HTML, CSS and JavaScript (JQuery Mobile) using Cordova, and now I would like to access the device database. Unfortunately I do not know where to start, because in the searches I did most of the material is in English (give Google translate). I would like a simple example of CRUD to be able to follow and tips for initiation as:

  • I have to grant access to the application to access the bank?

  • Is the information stored permanently on the device?

  • asked by anonymous 10.06.2015 / 22:19

    1 answer

    1

    There is a native sqlite interface in Cordova / PhoneGap

    cordova plugin add https://github.com/litehelpers/Cordova-sqlite-storage.git
    

    Example:

    module.controller('MyCtrl', function($scope, $cordovaSQLite) {
    
          var db = $cordovaSQLite.openDB({ name: "my.db" });
    
          // for opening a background db:
          var db = $cordovaSQLite.openDB({ name: "my.db", bgType: 1 });
    
          $scope.execute = function() {
            var query = "INSERT INTO test_table (data, data_num) VALUES (?,?)";
            $cordovaSQLite.execute(db, query, ["test", 100]).then(function(res) {
              console.log("insertId: " + res.insertId);
            }, function (err) {
              console.error(err);
            });
          };
    
        });
    

    link

        
    12.06.2015 / 13:36