import { log } from './FsOps' ; import Conversion from './Conversion' ; import DBAccess from './DBAccess' ; import DBAccessQueryResult from './DBAccessQueryResult' ; import DBVendors from './DBVendors' ; import IDBAccessQueryParams from './IDBAccessQueryParams' ; import { PoolClient } from 'pg' ; /**
 * Decodes binary data from from textual representation in string.
 */ export default async ( conversion ) : Promise < Conversion > => { const logTitle = 'BinaryDataDecoder::decodeBinaryData' ; log ( conversion , `\t--[${ logTitle }] Decodes binary data from textual representation in string.` ) ; const sql = `SELECT table_name, column_name 
        FROM information_schema.columns
        WHERE table_catalog = '${ conversion . _targetConString . database }' 
          AND table_schema = '${ conversion . _schema }' 
          AND data_type IN ('bytea', 'geometry');` ; const params = { conversion : conversion , caller : logTitle , sql : sql , vendor : DBVendors . PG , processExitOnError : false , shouldReturnClient : false } ; const result = await DBAccess . query ( params ) ; if ( result . error ) { await DBAccess . releaseDbClient ( conversion , < PoolClient > result . client ) ; return conversion ; } const decodePromises = result . data . rows . map ( async ( row ) => { const tableName = row . table_name ; const columnName = row . column_name ; params . sql = `UPDATE ${ conversion . _schema }."${ tableName }"
                SET "${ columnName }" = DECODE(ENCODE("${ columnName }", 'escape'), 'hex');` ; await DBAccess . query ( params ) ; } ) ; await Promise . all ( decodePromises ) ; return conversion ; } ;