Last active
April 7, 2016 22:15
-
-
Save pbernasconi/ebd1551c8c619fba0a9a to your computer and use it in GitHub Desktop.
ngCordova SQLite Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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