Page tree
Skip to end of metadata
Go to start of metadata

Availability

This API requires Profound.js version 4.15.0 or above.


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

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.
}