MCPcopy Create free account
hub / github.com/apache/cassandra-nodejs-driver / adaptNamedParamsWithHints

Function adaptNamedParamsWithHints

lib/utils.js:384–407  ·  view source on GitHub ↗

* Adapts the associative-array of parameters and hints for simple statements * into Arrays based on the (arbitrary) position of the keys. * @param {Array|Object} params * @param {ExecutionOptions} execOptions * @returns {{ params: Array<{name, value}>, namedParameters: boolean, keyIndexes: objec

(params, execOptions)

Source from the content-addressed store, hash-verified

382 * parameters and the keys as an associative array.
383 */
384function adaptNamedParamsWithHints(params, execOptions) {
385 if (!params || Array.isArray(params)) {
386 //The parameters is an Array or there isn't parameter
387 return { params: params, namedParameters: false, keyIndexes: null };
388 }
389
390 const keys = Object.keys(params);
391 const paramsArray = new Array(keys.length);
392 const hints = new Array(keys.length);
393 const userHints = execOptions.getHints() || emptyObject;
394 const keyIndexes = {};
395
396 for (let i = 0; i < keys.length; i++) {
397 const key = keys[i];
398 // As lower cased identifiers
399 paramsArray[i] = { name: key.toLowerCase(), value: params[key]};
400 hints[i] = userHints[key];
401 keyIndexes[key] = i;
402 }
403
404 execOptions.setHints(hints);
405
406 return { params: paramsArray, namedParameters: true, keyIndexes };
407}
408
409/**
410 * Returns a string with a value repeated n times

Callers

nothing calls this directly

Calls 3

keysMethod · 0.65
getHintsMethod · 0.65
setHintsMethod · 0.65

Tested by

no test coverage detected