Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 16 Current »

Content Freeze

As of July 25th, 2023, there is a content freeze on this page.

Availability

This API requires Profound.js version 4.15.0 or above.

When a Profound.js program is called from an IBM i job via PJSCALL or a proxy program, it's not possible to run multiple queries in parallel. In this scenario the queries will be run in sequence.


API Overview

The pjs.parallelQueries() API is a shortcut for executing multiple pjs.query() API's. The results are returned as a primitive JavaScript array.

Using this API can significantly improve performance.  These SQL statements are all initiated at the same time, rather than one at a time.

Input Parameter

This API can accept an optional database connection definition object to select between multiple database connections. To select the database connection, call pjs.getDB() and pass the result as the first parameter, followed by the parameters documented below. If a database connection definition object is not passed, the default database connection is used.

An array of SQL statements

  1. String - SQL statement
  2. Array - With the following elements [SQLStatement, token1, token2, etc...]
Returned Object

An array of objects,  In the below code example, qryResults will have 3 elements.

  • qryResults[0] - the results of running sql1
  • qryResults[1] - the results of running sql2
  • qryResults[2] - the results of running sql3

Each of those individual results is based on if that SQL statement was run successfully or not.  If successful, result will be an array of the data.  If not successful, result will be an object containing information about that failure.

Every SQL statement will be executed, and the result array sequence will match the parameter sequence.


function getData(request, response) {
    let id = request.query.id;
    let name = request.query.name;

    let sql1 = "select count(*) as total from productsp";                                // Simple sql string
    let sql2 = ["select * from productsp"];                                              // Simple sql string
    let sql3 = ["select * from productsp where productid = ? or prname = ?", id, name];  // SQL with where condition

    let qryResults = pjs.parallelQueries([sql1, sql2, sql3]);
    response.send(qryResults);

    // This will return a json array with 3 elements, because there were 3 queries.
    // And because each pjs.query returning an array -- then this qryResults would be an array of arrays.
}


  • No labels