function insertDays(days, cb) {
  const inserts = [];
  const daysKeys = Object.keys(days);

  if (!daysKeys || daysKeys.length === 0) {
    return cb(null, 0);
  }

  daysKeys.forEach((date) => {
    const day = days[date];
    day.currencies.forEach((currency) => {
      inserts.push([currency.iso, day.date, currency.buy, currency.sell]);
    });
  });

  const doInserts = (inserts, cb) => {
    db.connection().query(
      `INSERT INTO currencyDay(
      iso,
      date,
      buy,
      sell
    ) VALUES ?`,
      [inserts],
      (err, result) => {
        if (err) return cb(err);

        return cb(null, result.affectedRows);
      }
    );
  };

  let totalInsertedRows = 0;
  doInserts(inserts.splice(0, 200), function doInsertsCb(err, insertedRows) {
    if (err) {
      return cb(err);
    }

    totalInsertedRows += insertedRows;

    if (inserts.length) {
      doInserts(inserts.splice(0, 200), doInsertsCb);
    } else {
      cb(null, totalInsertedRows);
    }
  });
}
/**
 * Insert the array of days
 * @param {array} days Array of days, each with array of currencies
 * @param {function} cb The callback
 */
Insert the array of days
@param {array} days Array of days, each with array of currencies
@param {function} cb The callback
Insert the array of days @param { array } days Array of days each with array of currencies @param { function } cb The callback
function insertDays(days, cb) {
  const inserts = [];
  const daysKeys = Object.keys(days);
  if (!daysKeys || daysKeys.length === 0) {
    return cb(null, 0);
  }
  daysKeys.forEach((date) => {
    const day = days[date];
    day.currencies.forEach((currency) => {
      inserts.push([currency.iso, day.date, currency.buy, currency.sell]);
    });
  });
  const doInserts = (inserts, cb) => {
    db.connection().query(
      `INSERT INTO currencyDay(
      iso,
      date,
      buy,
      sell
    ) VALUES ?`,
      [inserts],
      (err, result) => {
        if (err) return cb(err);
        return cb(null, result.affectedRows);
      }
    );
  };
  let totalInsertedRows = 0;
  doInserts(inserts.splice(0, 200), function doInsertsCb(err, insertedRows) {
    if (err) {
      return cb(err);
    }
    totalInsertedRows += insertedRows;
    if (inserts.length) {
      doInserts(inserts.splice(0, 200), doInsertsCb);
    } else {
      cb(null, totalInsertedRows);
    }
  });
}
function insertDays ( days , cb ) { const inserts = [ ] ; const daysKeys = Object . keys ( days ) ; if ( ! daysKeys || daysKeys . length === 0 ) { return cb ( null , 0 ) ; } daysKeys . forEach ( ( date ) => { const day = days [ date ] ; day . currencies . forEach ( ( currency ) => { inserts . push ( [ currency . iso , day . date , currency . buy , currency . sell ] ) ; } ) ; } ) ; const doInserts = ( inserts , cb ) => { db . connection ( ) . query ( ` ` , [ inserts ] , ( err , result ) => { if ( err ) return cb ( err ) ; return cb ( null , result . affectedRows ) ; } ) ; } ; let totalInsertedRows = 0 ; doInserts ( inserts . splice ( 0 , 200 ) , function doInsertsCb ( err , insertedRows ) { if ( err ) { return cb ( err ) ; } totalInsertedRows += insertedRows ; if ( inserts . length ) { doInserts ( inserts . splice ( 0 , 200 ) , doInsertsCb ) ; } else { cb ( null , totalInsertedRows ) ; } } ) ; }
Insert the array of days
 @param {array} days Array of days, each with array of currencies
 @param {function} cb The callback
Insert the array of days @param { array } days Array of days each with array of currencies @param { function } cb The callback