index.js
function _transformToSafeValue(input, column){
  var out = input;
  var datatype = column.sql_type;
  var nullable = column.nullable;
  if( input === '' ){
    //empty string.
    if(datatype==='datetime'|| datatype==='timestamp' ||_.startsWith(datatype, 'int') || _.startsWith(datatype, 'num') || _.startsWith(datatype, 'dec')){
      if(nullable){
        out = null;
      } else {
        throw new Error(column.column + ' is not permitted to be empty.')
      }
    }

  } else if( !_.isNil(input) ) {
    //not null, not undefined
    if(datatype==='datetime'|| datatype==='timestamp'){
      out = moment(input).format('YYYY-MM-DD HH:mm:ss');
    }
  }
  return out;
}
function _transformToSafeValue(input, column){
  var out = input;
  var datatype = column.sql_type;
  var nullable = column.nullable;
  if( input === '' ){
    //empty string.
    if(datatype==='datetime'|| datatype==='timestamp' ||_.startsWith(datatype, 'int') || _.startsWith(datatype, 'num') || _.startsWith(datatype, 'dec')){
      if(nullable){
        out = null;
      } else {
        throw new Error(column.column + ' is not permitted to be empty.')
      }
    }

  } else if( !_.isNil(input) ) {
    //not null, not undefined
    if(datatype==='datetime'|| datatype==='timestamp'){
      out = moment(input).format('YYYY-MM-DD HH:mm:ss');
    }
  }
  return out;
}
function _transformToSafeValue ( input , column ) { var out = input ; var datatype = column . sql_type ; var nullable = column . nullable ; if ( input === '' ) { //empty string. if ( datatype === 'datetime' || datatype === 'timestamp' || _ . startsWith ( datatype , 'int' ) || _ . startsWith ( datatype , 'num' ) || _ . startsWith ( datatype , 'dec' ) ) { if ( nullable ) { out = null ; } else { throw new Error ( column . column + ' is not permitted to be empty.' ) } } } else if ( ! _ . isNil ( input ) ) { //not null, not undefined if ( datatype === 'datetime' || datatype === 'timestamp' ) { out = moment ( input ) . format ( 'YYYY-MM-DD HH:mm:ss' ) ; } } return out ; }
Helper that transforms input values to acceptable defaults for database columns.
Helper that transforms input values to acceptable defaults for database columns .