From 69e5f9eda89115c6efa948fdc99faa83362996c5 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 20 Oct 2015 08:47:43 +0000 Subject: [PATCH] fix simpleMap(rows) for find/getAll --- lib/dbwrap.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/dbwrap.js b/lib/dbwrap.js index 3f943b7..520d722 100644 --- a/lib/dbwrap.js +++ b/lib/dbwrap.js @@ -56,21 +56,11 @@ function wrap(db, dir) { } function simpleParse(row) { - var obj; - if (!row) { return null; } - if (row.json) { - obj = JSON.parse(row.json); - } else { - obj = {}; - } - - obj[idnameCased] = row[idname]; - - return obj; + return simpleMap([row])[0] || null; } function simpleMap(rows) { @@ -86,11 +76,20 @@ function wrap(db, dir) { if (row.json) { obj = JSON.parse(row.json); + delete row.json; } else { obj = {}; } obj[idnameCased] = row[idname]; + delete row[idname]; + + Object.keys(row).forEach(function (fieldname) { + // TODO warn if overriding proper field? (shouldn't be possible) + obj[camelCase(fieldname)] = row[fieldname]; + }); + + return obj; }); // set up for garbage collection rows.length = 0; @@ -129,7 +128,6 @@ function wrap(db, dir) { } } - console.log('sql', sql); return db.allAsync(sql, []).then(simpleMap); };