diff --git a/lib/dbwrap.js b/lib/dbwrap.js index c480e01..f7d2887 100644 --- a/lib/dbwrap.js +++ b/lib/dbwrap.js @@ -228,16 +228,19 @@ function wrap(db, dir, dbsMap) { DB.find = function (obj, params) { var err; - Object.keys(obj).forEach(function (key) { - if (undefined === obj[key]) { - err = new Error("'" + key + "' was `undefined'. For security purposes you must explicitly set the value to null or ''"); - } - }); + var sql = 'SELECT * FROM \'' + tablename + '\' '; + var keys = obj && Object.keys(obj); + + if (obj) { + Object.keys(obj).forEach(function (key) { + if (undefined === obj[key]) { + err = new Error("'" + key + "' was `undefined'. For security purposes you must explicitly set the value to null or ''"); + } + }); + } if (err) { return PromiseA.reject(err); } - var sql = 'SELECT * FROM \'' + tablename + '\' '; - var keys = obj && Object.keys(obj); if (obj && keys.length) { sql += 'WHERE '; @@ -255,7 +258,7 @@ function wrap(db, dir, dbsMap) { } }); } - else if (null !== obj1 || (params && !params.limit)) { + else if (null !== obj || (params && !params.limit)) { return PromiseA.reject(new Error("to find all you must explicitly specify find(null, { limit: <> })")); }