Skip to content

Instantly share code, notes, and snippets.

@gabrielem
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielem/27e2ae5aa8e4f90dfadc to your computer and use it in GitHub Desktop.
Save gabrielem/27e2ae5aa8e4f90dfadc to your computer and use it in GitHub Desktop.
(function(app){
var connect;
app.db = {};
var Database = app.db;
Database.initialize = function(){
db = window.sqlitePlugin.openDatabase({name: "DB.db", location: 2});
}
Database.findBy = function(params){
params = params || {};
var $deferred = $.Deferred();
var row=[];
//params.table
//params.where
db.transaction(function(tx) {
tx.executeSql('SELECT * FROM ' + params.table +';',[],
function(tx, results)
{
var totRes = results.rows.length;
for (var i=0; i < totRes; i++){
row[i] = results.rows.item(i);
}
$deferred.resolveWith(undefined,[row]);
},
function(tx, error)
{
$deferred.rejectwith(undefined,[error]);
}
);
}); return $deferred.promise();
}
})(app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment