All files / app/lib/bigquery index.js

16.66% Statements 4/24
100% Branches 1/1
0% Functions 0/1
16.66% Lines 4/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 2421x 21x                                         21x 21x
const Streamz = require('streamz');
 
function insert(table, options) {
  options = options || {};

  let cols = (async () => {
    var metadata = await table.getMetadata();
    cols = metadata[0].schema.fields.map(d => d.name);
    return cols;
  })();

  return Streamz(options.concurrency, async d => {
    await cols;
    const data = [].concat(d).map(d => {
      return cols.reduce( (p,col) => {
        if (d[col] !== undefined) p[col] = d[col];
        return p;
      },{});
    });
    await table.insert(data);  
  });
}
 
module.exports = {insert};