Last active
August 29, 2015 14:17
-
-
Save gabrielem/27e2ae5aa8e4f90dfadc to your computer and use it in GitHub Desktop.
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
(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