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

Method readMetadata

lib/readers.js:328–381  ·  view source on GitHub ↗

* Reads the metadata from a row or a prepared result response * @param {Number} kind * @returns {Object} * @throws {RangeError}

(kind)

Source from the content-addressed store, hash-verified

326 * @throws {RangeError}
327 */
328 readMetadata(kind) {
329 let i;
330 //Determines if its a prepared metadata
331 const isPrepared = (kind === types.resultKind.prepared);
332 const meta = {};
333 if (types.protocolVersion.supportsResultMetadataId(this.header.version) && isPrepared) {
334 meta.resultId = utils.copyBuffer(this.readShortBytes());
335 }
336 //as used in Rows and Prepared responses
337 const flags = this.readInt();
338 const columnLength = this.readInt();
339 if (types.protocolVersion.supportsPreparedPartitionKey(this.header.version) && isPrepared) {
340 //read the pk columns
341 meta.partitionKeys = new Array(this.readInt());
342 for (i = 0; i < meta.partitionKeys.length; i++) {
343 meta.partitionKeys[i] = this.readShort();
344 }
345 }
346 if (flags & resultFlag.hasMorePages) {
347 meta.pageState = utils.copyBuffer(this.readBytes());
348 }
349 if (flags & resultFlag.metadataChanged) {
350 meta.newResultId = utils.copyBuffer(this.readShortBytes());
351 }
352 if (flags & resultFlag.continuousPaging) {
353 meta.continuousPageIndex = this.readInt();
354 meta.lastContinuousPage = !!(flags & resultFlag.lastContinuousPage);
355 }
356 if (flags & resultFlag.globalTablesSpec) {
357 meta.global_tables_spec = true;
358 meta.keyspace = this.readString();
359 meta.table = this.readString();
360 }
361 meta.columns = new Array(columnLength);
362 meta.columnsByName = utils.emptyObject;
363 if (isPrepared) {
364 //for prepared metadata, we will need a index of the columns (param) by name
365 meta.columnsByName = {};
366 }
367 for (i = 0; i < columnLength; i++) {
368 const col = {};
369 if (!meta.global_tables_spec) {
370 col.ksname = this.readString();
371 col.tablename = this.readString();
372 }
373 col.name = this.readString();
374 col.type = this.readType();
375 meta.columns[i] = col;
376 if (isPrepared) {
377 meta.columnsByName[col.name] = i;
378 }
379 }
380 return meta;
381 }
382
383 /**
384 * Reads the error from the frame

Callers 1

streams.jsFile · 0.80

Calls 6

readShortBytesMethod · 0.95
readIntMethod · 0.95
readShortMethod · 0.95
readBytesMethod · 0.95
readStringMethod · 0.95
readTypeMethod · 0.95

Tested by

no test coverage detected