Was this page helpful?
concurrent¶
Utilities for concurrent query execution with the DataStax Node.js Driver.
Methods¶
(static) executeConcurrent(client, query, parameters, optionsopt) → {Promise:.<ResultSetGroup:>}
Executes multiple queries concurrently at the defined concurrency level.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
client |
Client | The Client instance. |
|||||||||||||||||||||||||||||||
query |
String | Array:.<{query:, params:}> | The query to execute per each parameter item. |
|||||||||||||||||||||||||||||||
parameters |
Array:.<Array:> | Stream | Object | An Array or a readable Stream composed of Array items representing each individual set of parameters. Per each item in the Array or Stream, an execution is going to be made. |
|||||||||||||||||||||||||||||||
options |
Object |
<optional> |
The execution options. Properties
|
Returns:
A Promise of ResultSetGroup that is resolved when all the
executions completed and it's rejected when raiseOnFirstError is true and there is one
or more failures.
Examples
Using a fixed query and an Array of Arrays as parameters
const query = 'INSERT INTO table1 (id, value) VALUES (?, ?)';
const parameters = [[1, 'a'], [2, 'b'], [3, 'c'], ]; // ...
const result = await executeConcurrent(client, query, parameters);Using a fixed query and a readable stream
const stream = csvStream.pipe(transformLineToArrayStream);
const result = await executeConcurrent(client, query, stream);Using a different queries
const queryAndParameters = [
{ query: 'INSERT INTO videos (id, name, user_id) VALUES (?, ?, ?)',
params: [ id, name, userId ] },
{ query: 'INSERT INTO user_videos (user_id, id, name) VALUES (?, ?, ?)',
params: [ userId, id, name ] },
{ query: 'INSERT INTO latest_videos (id, name, user_id) VALUES (?, ?, ?)',
params: [ id, name, userId ] },
];
const result = await executeConcurrent(client, queryAndParameters);