import { Encoding } from './Encoding' ; /**
 * Defines if given type is one of MySQL spacial types.
 */ const isSpacial = ( type ) : boolean => { return type . indexOf ( 'geometry' ) !== - 1 || type . indexOf ( 'point' ) !== - 1 || type . indexOf ( 'linestring' ) !== - 1 || type . indexOf ( 'polygon' ) !== - 1 ; } ; /**
 * Defines if given type is one of MySQL binary types.
 */ const isBinary = ( type ) : boolean => { return type . indexOf ( 'blob' ) !== - 1 || type . indexOf ( 'binary' ) !== - 1 ; } ; /**
 * Defines if given type is one of MySQL bit types.
 */ const isBit = ( type ) : boolean => { return type . indexOf ( 'bit' ) !== - 1 ; } ; /**
 * Defines if given type is one of MySQL date-time types.
 */ const isDateTime = ( type ) : boolean => { return type . indexOf ( 'timestamp' ) !== - 1 || type . indexOf ( 'date' ) !== - 1 ; } ; /**
 * Defines if given type is one of MySQL numeric types.
 */ const isNumeric = ( type ) : boolean => { return type . indexOf ( 'decimal' ) !== - 1 || type . indexOf ( 'numeric' ) !== - 1 || type . indexOf ( 'double' ) !== - 1 || type . indexOf ( 'float' ) !== - 1 || type . indexOf ( 'int' ) !== - 1 || type . indexOf ( 'point' ) !== - 1 ; } ; /**
 * Arranges columns data before loading.
 */ export default ( arrTableColumns , mysqlVersion , encoding ) : string => { let strRetVal = '' ; const wkbFunc = mysqlVersion >= 5.76 ? 'ST_AsWKB' : 'AsWKB' ; arrTableColumns . forEach ( ( column ) => { const field = column . Field ; const type = column . Type ; if ( isSpacial ( type ) ) { strRetVal += `HEX(${ wkbFunc }(\`${ field }\`)) AS \`${ field }\`,` ; } else if ( isBinary ( type ) ) { strRetVal += `HEX(\`${ field }\`) AS \`${ field }\`,` ; } else if ( isBit ( type ) ) { strRetVal += `BIN(\`${ field }\`) AS \`${ field }\`,` ; } else if ( isDateTime ( type ) ) { strRetVal += `IF(\`${ field }\` IN('0000-00-00', '0000-00-00 00:00:00'), '-INFINITY', CAST(\`${ field }\` AS CHAR)) AS \`${ field }\`,` ; } else if ( isNumeric ( type ) ) { strRetVal += `\`${ field }\` AS \`${ field }\`,` ; } else if ( encoding === 'utf-8' || encoding === 'utf8' ) { strRetVal += `REPLACE(\`${ field }\`, '\0', '') AS \`${ field }\`,` ; } else { strRetVal += `\`${ field }\` AS \`${ field }\`,` ; } } ) ; return strRetVal . slice ( 0 , - 1 ) ; } ;