import { types } from 'cassandra-driver' ; import { IKeyQueryOptions , ITableSchema } from '../../typings/cassandra' ; import { getBlobColumnNames } from './schema-utils' ; param row param columnNames param schema param options export function mapResultRow ( row , columnNames , schema , options ) { const { encoding , decodeValues } = options ; const blobColumns = getBlobColumnNames ( schema , false ) ; const blobPKs = getBlobColumnNames ( schema , true ) ; return columnNames . reduce ( ( prev , columnName ) => { let rowValue = row . get ( columnName ) ; if ( blobColumns . has ( columnName ) ) { if ( ! encoding || ( ! blobPKs . has ( columnName ) && ! decodeValues ) ) { return prev ; } if ( rowValue ) { const stringBuffer = ( rowValue as Buffer ) . toString ( encoding ) ; rowValue = encoding === 'hex' ? `0x${ stringBuffer }` : stringBuffer ; } else { rowValue = '' ; } } prev [ columnName ] = rowValue ; return prev ; } , { } as { [ columnName ] : any ; } ) ; }