diff --git a/lib/dbwrap.js b/lib/dbwrap.js index 3e09731..39c8364 100644 --- a/lib/dbwrap.js +++ b/lib/dbwrap.js @@ -226,7 +226,16 @@ function wrap(db, dir, dbsMap) { }); }; - DB.find = function (obj, params) { + DB.find = function (obj1, params) { + //var obj = obj1; + var obj = {}; + if (obj1) { + Object.keys(obj1).forEach(function (key) { + if (undefined !== obj1[key]) { + obj[key] = obj1[key]; + } + }); + } var sql = 'SELECT * FROM \'' + tablename + '\' '; var keys = obj && Object.keys(obj); @@ -242,13 +251,11 @@ function wrap(db, dir, dbsMap) { } else { // TODO check that key is some type? ignore undefined? - if (undefined === obj[key]) { - sql += db.escape(snakeCase(key)) + " = '" + db.escape(obj[key]) + "'"; - } + sql += db.escape(snakeCase(key)) + " = '" + db.escape(obj[key]) + "'"; } }); } - else if (null !== obj || (params && !params.limit)) { + else if (null !== obj1 || (params && !params.limit)) { return PromiseA.reject(new Error("to find all you must explicitly specify find(null, { limit: <> })")); }