Skip to content

Commit 769b60f

Browse files
Igor Drobiazkojhorbulyk
authored andcommitted
propert handling of columns
1 parent a41ab3c commit 769b60f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/actions/write.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ function init(cfg) {
2424
};
2525

2626
if (cfg.reader.columns) {
27-
console.log('Configured columns:', cfg.reader.columns);
28-
options.columns = cfg.reader.columns;
27+
28+
const columns = Object.keys(_.keyBy(cfg.reader.columns, 'property'));
29+
30+
console.log('Configured column names:', columns);
31+
options.columns = columns;
2932
}
3033

3134
stringifier = csv.stringify(options);
@@ -66,12 +69,15 @@ function processAction(msg, cfg) {
6669
console.log('Emitting message %j', messageToEmit);
6770
self.emit('data', messageToEmit);
6871

69-
yield init();
72+
yield init(cfg);
7073
});
7174
}, 10000);
7275

73-
const columns = cfg.reader.columns;
74-
const row = columns ? _.pick(msg.body, columns) : msg.body;
76+
let row = msg.body;
77+
if( cfg.reader.columns) {
78+
const columns = Object.keys(_.keyBy(cfg.reader.columns, 'property'));
79+
row = _.pick(msg.body, columns);
80+
}
7581
stringifier.write(row);
7682
rowCount++;
7783
this.emit('end');

0 commit comments

Comments
 (0)