lib/columns-to-model.js
function dataToType(data, name, options) {
  options = options || {};
  var knownID = /(^|\s|_)(zip|phone|id)(_|\s|$)/i;

  // If data is not a simple type, then just use text
  if (_.isArray(data[0]) || _.isObject(data[0])) {
    return Sequelize.TEXT;
  }

  // Otherise go through each value and see what is found
  data = _.map(data, function(d) {
    d = standardize(d);

    return {
      value: d,
      length: (d && d.toString) ? d.toString().length : null,
      kind: pickle(d, options)
    };
  });

  // Filter out any empty values
  data = _.filter(data, "length");
  var counted = _.countBy(data, "kind");
  var top = _.sortBy(_.map(counted, function(d, di) {
    return { kind: di, count: d };
  }), "count").reverse()[0];
  var maxLength = _.maxBy(data, "length");
  maxLength = maxLength ? maxLength.length : maxLength;
  var kind;

  // If none, then just assume string
  if (_.size(data) === 0) {
    return Sequelize.STRING;
  }
  // If there is only one kind, stick with that
  else if (_.size(counted) === 1) {
    kind = top.kind;
  }
  // If there is an integer and a float, use float
  else if (counted.INTGER && counted.FLOAT) {
    kind = "FLOAT";
  }
  else {
    kind = top.kind;
  }

  // Check for long strings
  if (kind === "STRING" && maxLength * 2 < 512) {
    return new Sequelize.STRING(Math.floor(maxLength * 2));
  }
  // Otherwise add length
  else if (kind === "STRING" && maxLength * 2 >= 512) {
    return Sequelize.TEXT;
  }
  // Known not numbers
  else if ((kind === "INTEGER" || kind === "FLOAT") && knownID.test(name)) {
    return new Sequelize.STRING(Math.floor(maxLength * 2));
  }
  // Check for long integers
  else if (kind === "INTEGER" && maxLength > 8) {
    return Sequelize.BIGINT;
  }
  else {
    return Sequelize[kind];
  }
}
function dataToType(data, name, options) {
  options = options || {};
  var knownID = /(^|\s|_)(zip|phone|id)(_|\s|$)/i;

  // If data is not a simple type, then just use text
  if (_.isArray(data[0]) || _.isObject(data[0])) {
    return Sequelize.TEXT;
  }

  // Otherise go through each value and see what is found
  data = _.map(data, function(d) {
    d = standardize(d);

    return {
      value: d,
      length: (d && d.toString) ? d.toString().length : null,
      kind: pickle(d, options)
    };
  });

  // Filter out any empty values
  data = _.filter(data, "length");
  var counted = _.countBy(data, "kind");
  var top = _.sortBy(_.map(counted, function(d, di) {
    return { kind: di, count: d };
  }), "count").reverse()[0];
  var maxLength = _.maxBy(data, "length");
  maxLength = maxLength ? maxLength.length : maxLength;
  var kind;

  // If none, then just assume string
  if (_.size(data) === 0) {
    return Sequelize.STRING;
  }
  // If there is only one kind, stick with that
  else if (_.size(counted) === 1) {
    kind = top.kind;
  }
  // If there is an integer and a float, use float
  else if (counted.INTGER && counted.FLOAT) {
    kind = "FLOAT";
  }
  else {
    kind = top.kind;
  }

  // Check for long strings
  if (kind === "STRING" && maxLength * 2 < 512) {
    return new Sequelize.STRING(Math.floor(maxLength * 2));
  }
  // Otherwise add length
  else if (kind === "STRING" && maxLength * 2 >= 512) {
    return Sequelize.TEXT;
  }
  // Known not numbers
  else if ((kind === "INTEGER" || kind === "FLOAT") && knownID.test(name)) {
    return new Sequelize.STRING(Math.floor(maxLength * 2));
  }
  // Check for long integers
  else if (kind === "INTEGER" && maxLength > 8) {
    return Sequelize.BIGINT;
  }
  else {
    return Sequelize[kind];
  }
}
function dataToType ( data , name , options ) { options = options || { } ; var knownID = / (^|\s|_)(zip|phone|id)(_|\s|$) / i ; // If data is not a simple type, then just use text if ( _ . isArray ( data [ 0 ] ) || _ . isObject ( data [ 0 ] ) ) { return Sequelize . TEXT ; } // Otherise go through each value and see what is found data = _ . map ( data , function ( d ) { d = standardize ( d ) ; return { value : d , length : ( d && d . toString ) ? d . toString ( ) . length : null , kind : pickle ( d , options ) } ; } ) ; // Filter out any empty values data = _ . filter ( data , "length" ) ; var counted = _ . countBy ( data , "kind" ) ; var top = _ . sortBy ( _ . map ( counted , function ( d , di ) { return { kind : di , count : d } ; } ) , "count" ) . reverse ( ) [ 0 ] ; var maxLength = _ . maxBy ( data , "length" ) ; maxLength = maxLength ? maxLength . length : maxLength ; var kind ; // If none, then just assume string if ( _ . size ( data ) === 0 ) { return Sequelize . STRING ; } // If there is only one kind, stick with that else if ( _ . size ( counted ) === 1 ) { kind = top . kind ; } // If there is an integer and a float, use float else if ( counted . INTGER && counted . FLOAT ) { kind = "FLOAT" ; } else { kind = top . kind ; } // Check for long strings if ( kind === "STRING" && maxLength * 2 < 512 ) { return new Sequelize . STRING ( Math . floor ( maxLength * 2 ) ) ; } // Otherwise add length else if ( kind === "STRING" && maxLength * 2 >= 512 ) { return Sequelize . TEXT ; } // Known not numbers else if ( ( kind === "INTEGER" || kind === "FLOAT" ) && knownID . test ( name ) ) { return new Sequelize . STRING ( Math . floor ( maxLength * 2 ) ) ; } // Check for long integers else if ( kind === "INTEGER" && maxLength > 8 ) { return Sequelize . BIGINT ; } else { return Sequelize [ kind ] ; } }
Data to type
Data to type