From ce430e63c0c222f5223363d2d5e2389c7e51874b Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 26 Mar 2016 17:03:19 -0400 Subject: [PATCH] overwrite new indexes with previous json value --- lib/dbwrap.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/dbwrap.js b/lib/dbwrap.js index cc67861..b9de65f 100644 --- a/lib/dbwrap.js +++ b/lib/dbwrap.js @@ -193,8 +193,15 @@ function wrap(db, dir, dbsMap) { delete row[idname]; Object.keys(row).forEach(function (fieldname) { - // TODO warn if overriding proper field? (shouldn't be possible) - obj[camelCase(fieldname)] = row[fieldname]; + // Ideally it shouldn't be possible to overriding a former proper column, + // but when a new indexable field is added, the old value is still in json + // TODO one-time upgrade of all rows when a new column is added + if (null === row[fieldname] || 'undefined' === typeof row[fieldname] || '' === row[fieldname]) { + obj[camelCase(fieldname)] = row[fieldname] || obj[camelCase(fieldname)] || row[fieldname]; + } + else { + obj[camelCase(fieldname)] = row[fieldname]; + } }); return obj;