text: /*
  SPDX-License-Identifier: Apache-2.0
  */
  
  'use strict';
  
  /*
   * Utility class for queries and query types
   */
  
  class Query {
  
  
  
    async getAllResults(iterator, isHistory) {
      let allResults = [];
      while (true) {
        let res = await iterator.next();
  
        if (res.value && res.value.value.toString()) {
          let jsonRes = {};
          console.log(res.value.value.toString('utf8'));
  
          if (isHistory && isHistory === true) {
            jsonRes.TxId = res.value.tx_id;
            jsonRes.Timestamp = res.value.timestamp;
            jsonRes.IsDelete = res.value.is_delete.toString();
            try {
              jsonRes.Value = JSON.parse(res.value.value.toString('utf8'));
            } catch (err) {
              console.log(err);
              jsonRes.Value = res.value.value.toString('utf8');
            }
          } else {
            jsonRes.Key = res.value.key;
            try {
              jsonRes.Record = JSON.parse(res.value.value.toString('utf8'));
            } catch (err) {
              console.log(err);
              jsonRes.Record = res.value.value.toString('utf8');
            }
          }
          allResults.push(jsonRes);
        }
        if (res.done) {
          console.log('end of data');
          await iterator.close();
          console.info(allResults);
          return allResults;
        }
      }  // if 
    } // while
  
  };  // class
  
  module.exports = Query;
  