如果查询有多个输入,如何在 Hyperledger composer logic.js 中使用查询?

How to use query in Hyperledger composer logic.js if the query have multiple inputs?

用于在 logic.js 中查询我可以使用

await query('selectCommoditiesWithHighQuantity')

但是如果我有多个输入怎么办呢? 如果查询具有这样的功能

query selectCommoditiesByTimeAndOwnerAndDataType {
  description: "Select all commodities based on their sender country"
  statement:
      SELECT org.stock.mynetwork.Commodity
          WHERE(time  > _$from AND time < _$to AND owner == _$owner AND dataType == _$dataType)
}

如何从 js 端调用该查询?

编辑: js代码

/**
 * Track the trade of a commodity from one trader to another
 * @param {org.stock.mynetwork.Receive} receive - the receive to be processed
 * @transaction
 */
async function receiveCommodity(receive) {

    let q1 = await buildQuery('SELECT org.stock.mynetwork.Commodity ' +
                                                'WHERE (productName == _$productName AND owner == _$owner)');


let result2 = await query(q1,{productName:receive.productName,owner: receive.newOwner});
}

let result2 = await query(q1,{productName:receive.productName,owner: receive.newOwner}); 部分有问题。如果我只使用 productName: receive.productName 它完美地工作,但是当我添加 owner: receive.newOwner 它需要 serialize.json

因此您可以在 .qry 文件中编写一个查询并调用它,但我不建议这样做。您可以直接从 SDK 和 logic.js 文件中进行相同的查询。这背后的原因是,比如说几天后,你想添加一个新的 API 来查询某个值,如果你依赖 .qry 文件(这会起作用),那么你将需要部署新版本的智能联系人,而如果您使用 SDK,则可以在 API 中进行更改并尽快部署新的应用程序服务器。

async function someTransaction(receive) {
  let assetRegistry = await getAssetRegistry('YOUR_NAME_SPACE');
  let ownerRegistry = await getParticipantRegistry('YOUR_NAME_SPACE');

  let statement = 'SELECT NAME_SPACE_OF_ASSET WHERE (owner == _$owner && dataType == _$dataType)';
  let qry = buildQuery(statement);

  // This query can be done in different ways
  // assuming newOwner is a string (id of participant)
  let allAssets = await query(qry, { owner: receive.newOwner, dataType: receive.dataType });

  // assuming newOwner is a participant
  let allAssets = await query(qry, { owner: receive.newOwner.getIdentifier(), dataType: receive.dataType });

  if (allAssets.length === 0) {
    // No assets exists, add one
    // use assetRegistry.add()
  } else {
    for (var i = 0; i < allAssets.length; i++) {
      // Iterate over assets belonging to an owner of a product type
      // Do whatever here
      // use assetRegistry.update()
    };
  };

};