import { log } from './FsOps' ; import arrangeColumnsData from './ColumnsDataArranger' ; import * as extraConfigProcessor from './ExtraConfigProcessor' ; import Conversion from './Conversion' ; import DBAccess from './DBAccess' ; import DBAccessQueryResult from './DBAccessQueryResult' ; import DBVendors from './DBVendors' ; import IDBAccessQueryParams from './IDBAccessQueryParams' ; import { getDataPoolTableName } from './DataPoolManager' ; /**
 * Prepares an array of tables metadata.
 */ export default async ( conversion , tableName , haveDataChunksProcessed ) : Promise < void > => { if ( haveDataChunksProcessed ) { return ; } const originalTableName = extraConfigProcessor . getTableName ( conversion , tableName , true ) ; const logTitle = 'DataChunksProcessor::default' ; const selectFieldList = arrangeColumnsData ( conversion . _dicTables [ tableName ] . arrTableColumns , conversion . _mysqlVersion , conversion . _encoding ) ; const sqlRowsCnt = `SELECT COUNT(1) AS rows_count FROM \`${ originalTableName }\`;` ; const params = { conversion : conversion , caller : 'DataChunksProcessor::default' , sql : sqlRowsCnt , vendor : DBVendors . MYSQL , processExitOnError : false , shouldReturnClient : false } ; const countResult = await DBAccess . query ( params ) ; const rowsCnt = countResult . data [ 0 ] . rows_count ; const msg = `\t--[${ logTitle }] Total rows to insert into "${ conversion . _schema }"."${ tableName }": ${ rowsCnt }` ; log ( conversion , msg , conversion . _dicTables [ tableName ] . tableLogPath ) ; const metadata = JSON . stringify ( { _tableName : tableName , _selectFieldList : selectFieldList , _rowsCnt : rowsCnt , } ) ; params . sql = `INSERT INTO ${ getDataPoolTableName ( conversion ) }("metadata") VALUES ($1);` ; params . vendor = DBVendors . PG ; params . client = undefined ; params . bindings = [ metadata ] ; await DBAccess . query ( params ) ; } ;