lib/actions/addData.js
/**
 * This method will be called from elastic.io platform providing following data
 *
 * @param msg incoming message object that contains ``body`` with payload
 * @param cfg configuration that is account information and configuration field values
 */
This method will be called from elastic.io platform providing following data
@param msg incoming message object that contains ``body`` with payload
@param cfg configuration that is account information and configuration field values
This method will be called from elastic . io platform providing following data @param msg incoming message object that contains ` ` body ` ` with payload @param cfg configuration that is account information and configuration field values
async function processAction(msg, cfg) {
  function handleResult(result) {
    console.log('Result:', result);
  }
  try {
    const transformedMsg = transform(msg, cfg);
    console.log(transformedMsg);
    const {
       domainId,
       schema,
      query,
      databaseType,
    } = cfg;
     const oihMeta = {
       applicationUid,
       oihUid,
       recordUid,
     };
    const oihMeta = {};
    const [realQuery,uidIDS] = fillQueryIDS(query, transformedMsg);
    console.log('realQuery:', realQuery);
    let reply;
    if (databaseType) {
      const dbType = databaseType.toLowerCase();
      if (dbType === 'mysql') {
        reply = mysqlExecute(cfg, realQuery, handleResult);
      } else if (dbType === 'postgresql') {
        reply = postgreExecute(cfg, realQuery, handleResult);
      } else if (dbType === 'mssql' || dbType === 'sql') {
        reply = mssqlExecute(cfg, realQuery, handleResult);
      } else {
        console.error(`Unknown database type [${databaseType}] falling back to MySQL`);
        reply = mysqlExecute(cfg, realQuery, handleResult);
      }
    } else {
      console.error('No database type set asuming MySQL');
      reply = mysqlExecute(cfg, realQuery, handleResult);
    }
    const response = {
      metadata: oihMeta,
      data: uidIDS,
    };
    this.emit('data', response)
    console.log('Response:', response);
  } catch (e) {
    console.log('Oops! Error occurred');
    this.emit('error', e);
  }
}
async function processAction ( msg , cfg ) { function handleResult ( result ) { console . log ( 'Result:' , result ) ; } try { const transformedMsg = transform ( msg , cfg ) ; console . log ( transformedMsg ) ; const { query , databaseType , } = cfg ; const oihMeta = { } ; const [ realQuery , uidIDS ] = fillQueryIDS ( query , transformedMsg ) ; console . log ( 'realQuery:' , realQuery ) ; let reply ; if ( databaseType ) { const dbType = databaseType . toLowerCase ( ) ; if ( dbType === 'mysql' ) { reply = mysqlExecute ( cfg , realQuery , handleResult ) ; } else if ( dbType === 'postgresql' ) { reply = postgreExecute ( cfg , realQuery , handleResult ) ; } else if ( dbType === 'mssql' || dbType === 'sql' ) { reply = mssqlExecute ( cfg , realQuery , handleResult ) ; } else { console . error ( ` ${ databaseType } ` ) ; reply = mysqlExecute ( cfg , realQuery , handleResult ) ; } } else { console . error ( 'No database type set asuming MySQL' ) ; reply = mysqlExecute ( cfg , realQuery , handleResult ) ; } const response = { metadata : oihMeta , data : uidIDS , } ; this . emit ( 'data' , response ) console . log ( 'Response:' , response ) ; } catch ( e ) { console . log ( 'Oops! Error occurred' ) ; this . emit ( 'error' , e ) ; } }
This method will be called from elastic.io platform providing following data
 @param msg incoming message object that contains ``body`` with payload
 @param cfg configuration that is account information and configuration field values
This method will be called from elastic . io platform providing following data @param msg incoming message object that contains ` ` body ` ` with payload @param cfg configuration that is account information and configuration field values
// const oihUid = (transformedMsg.meta !== undefined && transformedMsg.meta !== undefined) //   ? transformedMsg.meta.oihUid : undefined; // const recordUid = (transformedMsg !== undefined && transformedMsg.meta !== undefined) //   ? transformedMsg.meta.recordUid : undefined; // const applicationUid = (transformedMsg.meta !== undefined && transformedMsg.meta !== undefined) //   ? transformedMsg.meta.applicationUid : undefined; // // domainId, // schema, /** The following block creates the meta object.
   *  This meta object stores information which are
   *  later needed in order to make the hub and spoke architecture work properly
   */ // const oihMeta = { //   applicationUid, //   oihUid, //   recordUid, // }; /*
    const data = response;
    this.emit('data', data);*/