Skip to content

Instantly share code, notes, and snippets.

@pbernasconi
Last active April 7, 2016 22:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pbernasconi/ebd1551c8c619fba0a9a to your computer and use it in GitHub Desktop.
Save pbernasconi/ebd1551c8c619fba0a9a to your computer and use it in GitHub Desktop.
ngCordova SQLite Plugin
angular.module('ngCordova.plugins.sqlite', [])
.factory('$cordovaSQLite', ['$q', function ($q) {
return {
openDB: function(dbName) {
return window.sqlitePlugin.openDatabase({name: dbName});
},
openDBBackground: function(dbName) {
return window.sqlitePlugin.openDatabase({name: dbName, bgType: 1});
},
execute: function (db, query, binding) {
q = $q.defer();
db.transaction(function(tx) {
tx.executeSql(query, binding, function(tx, result) {
q.resolve(result);
},
function(transaction, error) {
q.reject(error);
});
})
return q.promise;
},
nestedExecute: function (db, query1, query2, binding1, binding2) {
q = $q.defer();
db.transaction( function(tx) {
tx.executeSql(query1, binding1, function(tx, result) {
q.resolve(result);
tx.executeSql(query2, binding2, function(tx, res) {
q.resolve(res);
}
}
},
function(transaction, error) {
q.reject(error);
});
})
return q.promise;
}
// more methods here
}
}]);
@igorcosta
Copy link

How do you handle async calls, since transactions in websql are transactions, I had a problem regarding this field when I tried to scope change a variable based on a result of transaction.

@jdnichollsc
Copy link

Is very easy with SQLite (Tested with pre-filled databases with 25000 records), see my example: https://github.com/jdnichollsc/Ionic-Starter-Template

Regards, Nicholls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment