Skip to content

Instantly share code, notes, and snippets.

@jabyrd3
Created June 4, 2014 01:06
Show Gist options
  • Save jabyrd3/0df02fffd1caaca83485 to your computer and use it in GitHub Desktop.
Save jabyrd3/0df02fffd1caaca83485 to your computer and use it in GitHub Desktop.
Quick db abstract for working with cordova / AngularJS
/* Services */
var myApp = angular.module('myApp.services', []);
myApp.service('DB', function($window) {
//var query = 'SELECT DISTINCT(prod_category) FROM prod_master';
var dbConn = $window.sqlitePlugin.openDatabase({
name: "hd_app.sqlite"
});
var chewer = function(tx, res, callback) {
var resultSet = [];
for (var i = 0; i < res.rows.length; i++) {
var objPush = {
prodcategory: res.rows.item(i).prod_category
};
resultSet.push(objPush);
};
callback(resultSet);
};
return{
query: function(query, callback){
dbConn.transaction(function(tx){
tx.executeSql(query, [], function(tx, res){
chewer(tx, res, callback);
});
}, function(e) {
console.log("ERROR: " + e.message);
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment