Created
June 4, 2014 01:06
-
-
Save jabyrd3/0df02fffd1caaca83485 to your computer and use it in GitHub Desktop.
Quick db abstract for working with cordova / AngularJS
This file contains hidden or 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
/* 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