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); };