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

Method getFunctions

lib/metadata/schema-parser.js:291–336  ·  view source on GitHub ↗

* @param {String} keyspaceName * @param {String} name * @param {Boolean} aggregate * @param {Object} cache * @returns {Promise }

(keyspaceName, name, aggregate, cache)

Source from the content-addressed store, hash-verified

289 * @returns {Promise<Map>}
290 */
291 async getFunctions(keyspaceName, name, aggregate, cache) {
292 /** @type {String} */
293 let query = this.selectFunctions;
294 let parser = row => this._parseFunction(row);
295 if (aggregate) {
296 query = this.selectAggregates;
297 parser = row => this._parseAggregate(row);
298 }
299 // if it's not already loaded, get all functions with that name
300 // cache it by name and, within name, by signature
301 let functionsInfo = cache && cache[name];
302 if (!functionsInfo) {
303 functionsInfo = new events.EventEmitter();
304 if (cache) {
305 cache[name] = functionsInfo;
306 }
307 functionsInfo.setMaxListeners(0);
308 }
309 if (functionsInfo.values) {
310 return functionsInfo.values;
311 }
312 if (functionsInfo.loading) {
313 return promiseUtils.fromEvent(functionsInfo, 'load');
314 }
315 functionsInfo.loading = true;
316 try {
317 const rows = await this._getRows(format(query, keyspaceName, name));
318 const funcs = await Promise.all(rows.map(parser));
319 const result = new Map();
320 if (rows.length > 0) {
321 // Cache positive hits
322 functionsInfo.values = result;
323 }
324
325 funcs.forEach(f => functionsInfo.values.set(f.signature.join(','), f));
326 functionsInfo.emit('load', null, result);
327 return result;
328 }
329 catch (err) {
330 functionsInfo.emit('load', err);
331 throw err;
332 }
333 finally {
334 functionsInfo.loading = false;
335 }
336 }
337
338 /**
339 * @abstract

Callers

nothing calls this directly

Calls 4

_parseAggregateMethod · 0.95
_getRowsMethod · 0.95
setMethod · 0.80
forEachMethod · 0.65

Tested by

no test coverage detected