From 2501c2fd4d7a7269240e6d676b79b17a91329863 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 23 Mar 2016 03:38:59 +0000 Subject: [PATCH] fix syntax bug --- lib/dbwrap.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) 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: <> })")); }