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;