lib/connection/result/result.js
function Result(options)
{
  var data;
  var chunkHeaders;
  var parametersMap;
  var parametersArray;
  var length;
  var index;
  var parameter;
  var mapColumnNameToIndices;
  var columns;
  var column;

  // assert that options is a valid object that contains a response, statement,
  // services and connection config
  Errors.assertInternal(Util.isObject(options));
  Errors.assertInternal(Util.isObject(options.response));
  Errors.assertInternal(Util.isObject(options.statement));
  Errors.assertInternal(Util.isObject(options.services));
  Errors.assertInternal(Util.isObject(options.connectionConfig));

  // save the statement, services and connection config
  this._statement        = options.statement;
  this._services         = options.services;
  this._connectionConfig = options.connectionConfig;

  data = options.response.data;

  this._statementId     = data.queryId;
  this._version         = version = String(data.version); // don't rely on the version being a number
  this._returnedRows    = data.returned;
  this._totalRows       = data.total;
  this._statementTypeId = data.statementTypeId;

  // if no chunk headers were specified, but a query-result-master-key (qrmk)
  // was specified, build the chunk headers from the qrmk
  chunkHeaders = data.chunkHeaders;
  if (!Util.isObject(chunkHeaders) && Util.isString(data.qrmk))
  {
    chunkHeaders =
    {
      'x-amz-server-side-encryption-customer-algorithm': 'AES256',
      'x-amz-server-side-encryption-customer-key': data.qrmk
    };
  }
  this._chunkHeaders = chunkHeaders;

  // build a session state object from the response data; this can be used to
  // get the values of the current role, current warehouse, current database,
  // etc.
  this._sessionState = createSessionState(data);

  // convert the parameters array to a map
  parametersMap = {};
  parametersArray = data.parameters;
  for (index = 0, length = parametersArray.length; index < length; index++)
  {
    parameter = parametersArray[index];
    parametersMap[parameter.name] = parameter.value;
  }

  // save the parameters array
  this._parametersArray = parametersArray;

  // TODO: add timezone related information to columns

  // create columns from the rowtype array returned in the result
  var rowtype = data.rowtype;
  var numColumns = rowtype.length;

  this._columns = columns = new Array(numColumns);

  // convert the rowtype array to an array of columns and build an inverted
  // index map in which the keys are the column names and the values are the
  // indices of the columns with the corresponding names
  this._mapColumnNameToIndices = mapColumnNameToIndices = {};
  for (index = 0; index < numColumns; index++)
  {
    // create a new column and add it to the columns array
    columns[index] = column =
        new Column(rowtype[index], index, parametersMap, version);

    // if we don't already have an index array for a column with this name,
    // create a new one, otherwise just append to the existing array of indices
    mapColumnNameToIndices[column.getName()] =
        mapColumnNameToIndices[column.getName()] || [];
    mapColumnNameToIndices[column.getName()].push(index);
  }

  // create chunks
  this._chunks = createChunks(
      data.chunks,
      data.rowset,
      this._columns,
      this._mapColumnNameToIndices,
      this._chunkHeaders,
      parametersMap,
      this._version,
      this._statement,
      this._services);

  // create a chunk cache and save a reference to it in case we need to
  // TODO: should we be clearing the cache at some point, e.g. when the result
  // is destroyed?
  this._chunkCache = createChunkCache(
      this._chunks,
      this._connectionConfig.getResultChunkCacheSize());
}
function Result(options)
{
  var data;
  var chunkHeaders;
  var parametersMap;
  var parametersArray;
  var length;
  var index;
  var parameter;
  var mapColumnNameToIndices;
  var columns;
  var column;

  // assert that options is a valid object that contains a response, statement,
  // services and connection config
  Errors.assertInternal(Util.isObject(options));
  Errors.assertInternal(Util.isObject(options.response));
  Errors.assertInternal(Util.isObject(options.statement));
  Errors.assertInternal(Util.isObject(options.services));
  Errors.assertInternal(Util.isObject(options.connectionConfig));

  // save the statement, services and connection config
  this._statement        = options.statement;
  this._services         = options.services;
  this._connectionConfig = options.connectionConfig;

  data = options.response.data;

  this._statementId     = data.queryId;
  this._version         = version = String(data.version); // don't rely on the version being a number
  this._returnedRows    = data.returned;
  this._totalRows       = data.total;
  this._statementTypeId = data.statementTypeId;

  // if no chunk headers were specified, but a query-result-master-key (qrmk)
  // was specified, build the chunk headers from the qrmk
  chunkHeaders = data.chunkHeaders;
  if (!Util.isObject(chunkHeaders) && Util.isString(data.qrmk))
  {
    chunkHeaders =
    {
      'x-amz-server-side-encryption-customer-algorithm': 'AES256',
      'x-amz-server-side-encryption-customer-key': data.qrmk
    };
  }
  this._chunkHeaders = chunkHeaders;

  // build a session state object from the response data; this can be used to
  // get the values of the current role, current warehouse, current database,
  // etc.
  this._sessionState = createSessionState(data);

  // convert the parameters array to a map
  parametersMap = {};
  parametersArray = data.parameters;
  for (index = 0, length = parametersArray.length; index < length; index++)
  {
    parameter = parametersArray[index];
    parametersMap[parameter.name] = parameter.value;
  }

  // save the parameters array
  this._parametersArray = parametersArray;

  // TODO: add timezone related information to columns

  // create columns from the rowtype array returned in the result
  var rowtype = data.rowtype;
  var numColumns = rowtype.length;

  this._columns = columns = new Array(numColumns);

  // convert the rowtype array to an array of columns and build an inverted
  // index map in which the keys are the column names and the values are the
  // indices of the columns with the corresponding names
  this._mapColumnNameToIndices = mapColumnNameToIndices = {};
  for (index = 0; index < numColumns; index++)
  {
    // create a new column and add it to the columns array
    columns[index] = column =
        new Column(rowtype[index], index, parametersMap, version);

    // if we don't already have an index array for a column with this name,
    // create a new one, otherwise just append to the existing array of indices
    mapColumnNameToIndices[column.getName()] =
        mapColumnNameToIndices[column.getName()] || [];
    mapColumnNameToIndices[column.getName()].push(index);
  }

  // create chunks
  this._chunks = createChunks(
      data.chunks,
      data.rowset,
      this._columns,
      this._mapColumnNameToIndices,
      this._chunkHeaders,
      parametersMap,
      this._version,
      this._statement,
      this._services);

  // create a chunk cache and save a reference to it in case we need to
  // TODO: should we be clearing the cache at some point, e.g. when the result
  // is destroyed?
  this._chunkCache = createChunkCache(
      this._chunks,
      this._connectionConfig.getResultChunkCacheSize());
}
function Result ( options ) { var data ; var chunkHeaders ; var parametersMap ; var parametersArray ; var length ; var index ; var parameter ; var mapColumnNameToIndices ; var columns ; var column ; // assert that options is a valid object that contains a response, statement, // services and connection config Errors . assertInternal ( Util . isObject ( options ) ) ; Errors . assertInternal ( Util . isObject ( options . response ) ) ; Errors . assertInternal ( Util . isObject ( options . statement ) ) ; Errors . assertInternal ( Util . isObject ( options . services ) ) ; Errors . assertInternal ( Util . isObject ( options . connectionConfig ) ) ; // save the statement, services and connection config this . _statement = options . statement ; this . _services = options . services ; this . _connectionConfig = options . connectionConfig ; data = options . response . data ; this . _statementId = data . queryId ; this . _version = version = String ( data . version ) ; // don't rely on the version being a number this . _returnedRows = data . returned ; this . _totalRows = data . total ; this . _statementTypeId = data . statementTypeId ; // if no chunk headers were specified, but a query-result-master-key (qrmk) // was specified, build the chunk headers from the qrmk chunkHeaders = data . chunkHeaders ; if ( ! Util . isObject ( chunkHeaders ) && Util . isString ( data . qrmk ) ) { chunkHeaders = { 'x-amz-server-side-encryption-customer-algorithm' : 'AES256' , 'x-amz-server-side-encryption-customer-key' : data . qrmk } ; } this . _chunkHeaders = chunkHeaders ; // build a session state object from the response data; this can be used to // get the values of the current role, current warehouse, current database, // etc. this . _sessionState = createSessionState ( data ) ; // convert the parameters array to a map parametersMap = { } ; parametersArray = data . parameters ; for ( index = 0 , length = parametersArray . length ; index < length ; index ++ ) { parameter = parametersArray [ index ] ; parametersMap [ parameter . name ] = parameter . value ; } // save the parameters array this . _parametersArray = parametersArray ; // TODO: add timezone related information to columns // create columns from the rowtype array returned in the result var rowtype = data . rowtype ; var numColumns = rowtype . length ; this . _columns = columns = new Array ( numColumns ) ; // convert the rowtype array to an array of columns and build an inverted // index map in which the keys are the column names and the values are the // indices of the columns with the corresponding names this . _mapColumnNameToIndices = mapColumnNameToIndices = { } ; for ( index = 0 ; index < numColumns ; index ++ ) { // create a new column and add it to the columns array columns [ index ] = column = new Column ( rowtype [ index ] , index , parametersMap , version ) ; // if we don't already have an index array for a column with this name, // create a new one, otherwise just append to the existing array of indices mapColumnNameToIndices [ column . getName ( ) ] = mapColumnNameToIndices [ column . getName ( ) ] || [ ] ; mapColumnNameToIndices [ column . getName ( ) ] . push ( index ) ; } // create chunks this . _chunks = createChunks ( data . chunks , data . rowset , this . _columns , this . _mapColumnNameToIndices , this . _chunkHeaders , parametersMap , this . _version , this . _statement , this . _services ) ; // create a chunk cache and save a reference to it in case we need to // TODO: should we be clearing the cache at some point, e.g. when the result // is destroyed? this . _chunkCache = createChunkCache ( this . _chunks , this . _connectionConfig . getResultChunkCacheSize ( ) ) ; }
Creates a new Result.

@param {Object} options
@constructor
Creates a new Result .