lib/field.mysql.js
function finishSpec(spec, opts, field) {
  if (opts.unique) {
    var keylength = parseInt(opts.unique, 10) ? opts.unique : undefined;
    
    if (opts.unique === true && spec.sql.match(/^(text|blob)/i)) {
      var msg = 'When adding a unique key to an unsized type (text or blob), unique must be set with a length e.g. { unique: 128 }';
      throw new Error(msg);
    }

    spec.keysql = _.strjoin(
      _.upcase('unique key'),
      _.backtick(field),
      _.paren(_.strjoin(
        _.backtick(field),
        _.paren(keylength)
      ))
    );
  }

  if (opts['null'] === false || opts.required === true) {
    spec.sql = _.strjoin(spec.sql, 'NOT NULL');
    spec.validators.unshift(Validators.Require);
  }

  if (opts['default'] !== undefined) {
    var defval = opts['default'];
    var textType = opts.type.match(/blob|text|char|enum|binary/i);
    spec.sql = _.strjoin(
      spec.sql,
      'DEFAULT',
      (textType ? _.quote(defval) : defval)
    );
  }
  
  return spec;
}
function finishSpec(spec, opts, field) {
  if (opts.unique) {
    var keylength = parseInt(opts.unique, 10) ? opts.unique : undefined;
    
    if (opts.unique === true && spec.sql.match(/^(text|blob)/i)) {
      var msg = 'When adding a unique key to an unsized type (text or blob), unique must be set with a length e.g. { unique: 128 }';
      throw new Error(msg);
    }

    spec.keysql = _.strjoin(
      _.upcase('unique key'),
      _.backtick(field),
      _.paren(_.strjoin(
        _.backtick(field),
        _.paren(keylength)
      ))
    );
  }

  if (opts['null'] === false || opts.required === true) {
    spec.sql = _.strjoin(spec.sql, 'NOT NULL');
    spec.validators.unshift(Validators.Require);
  }

  if (opts['default'] !== undefined) {
    var defval = opts['default'];
    var textType = opts.type.match(/blob|text|char|enum|binary/i);
    spec.sql = _.strjoin(
      spec.sql,
      'DEFAULT',
      (textType ? _.quote(defval) : defval)
    );
  }
  
  return spec;
}
function finishSpec ( spec , opts , field ) { if ( opts . unique ) { var keylength = parseInt ( opts . unique , 10 ) ? opts . unique : undefined ; if ( opts . unique === true && spec . sql . match ( / ^(text|blob) / i ) ) { var msg = 'When adding a unique key to an unsized type (text or blob), unique must be set with a length e.g. { unique: 128 }' ; throw new Error ( msg ) ; } spec . keysql = _ . strjoin ( _ . upcase ( 'unique key' ) , _ . backtick ( field ) , _ . paren ( _ . strjoin ( _ . backtick ( field ) , _ . paren ( keylength ) ) ) ) ; } if ( opts [ 'null' ] === false || opts . required === true ) { spec . sql = _ . strjoin ( spec . sql , 'NOT NULL' ) ; spec . validators . unshift ( Validators . Require ) ; } if ( opts [ 'default' ] !== undefined ) { var defval = opts [ 'default' ] ; var textType = opts . type . match ( / blob|text|char|enum|binary / i ) ; spec . sql = _ . strjoin ( spec . sql , 'DEFAULT' , ( textType ? _ . quote ( defval ) : defval ) ) ; } return spec ; }
Helper for handling generic options for field generators.

@param {Object} spec
@param {Object} opts see below
@param {String} field

@param {Boolean} opts.null when false, adds `required` validator,
`not null` to field
@param {Boolean} opts.required opposite of `opts.null`
@param {Boolean|Integer} opts.unique integer specifies length of key
@param {String|Number} opts.default the default value for the field
Helper for handling generic options for field generators .