fix simpleMap(rows) for find/getAll

This commit is contained in:
AJ ONeal 2015-10-20 08:47:43 +00:00
parent 5119cb1bf0
commit 69e5f9eda8
1 changed files with 10 additions and 12 deletions

View File

@ -56,21 +56,11 @@ function wrap(db, dir) {
} }
function simpleParse(row) { function simpleParse(row) {
var obj;
if (!row) { if (!row) {
return null; return null;
} }
if (row.json) { return simpleMap([row])[0] || null;
obj = JSON.parse(row.json);
} else {
obj = {};
}
obj[idnameCased] = row[idname];
return obj;
} }
function simpleMap(rows) { function simpleMap(rows) {
@ -86,11 +76,20 @@ function wrap(db, dir) {
if (row.json) { if (row.json) {
obj = JSON.parse(row.json); obj = JSON.parse(row.json);
delete row.json;
} else { } else {
obj = {}; obj = {};
} }
obj[idnameCased] = row[idname]; 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 // set up for garbage collection
rows.length = 0; rows.length = 0;
@ -129,7 +128,6 @@ function wrap(db, dir) {
} }
} }
console.log('sql', sql);
return db.allAsync(sql, []).then(simpleMap); return db.allAsync(sql, []).then(simpleMap);
}; };