Query Language : Query request on reference

放肆的年华 提交于 2019-12-10 10:56:24

问题


Following the tutorial, there is the query

query selectCommoditiesByOwner {
  description: "Select all commodities based on their owner"
  statement:
      SELECT org.acme.biznet.Commodity
          WHERE (owner == _$owner)
}

But nowhere is an example explaining how to request it

For the parameter owner, I tryed with the node variable owner

  • owner.toUri()
  • owner.getFullyQualifiedIdentifier()
  • "resource:" + owner.getFullyQualifiedIdentifier()

But nothing works

Does somebody has a working example?


回答1:


Example on how to 'request it' is shown in the REST API section of the Queries tutorial https://hyperledger.github.io/composer/tutorials/queries

If you mean: request it from within a Transaction Processor function, using the APIs - there is an example in the same tutorial, of calling a Query function eg.

/**
 * Remove all high volume commodities
 * @param {org.acme.biznet.RemoveHighQuantityCommodities} remove - the remove to be processed
 * @transaction
 */

function removeHighQuantityCommodities(remove) {

return getAssetRegistry('org.acme.biznet.Commodity')
    .then(function (assetRegistry) {
        return query('selectCommoditiesWithHighQuantity')
            .then(function (results) {
           // process results objects etc

so using your query - you might do something like:

var tx_owner = tx.owner; // passed into the Transaction Processor for example
return query('selectCommoditiesByOwner', {
   "owner": tx_owner    // eg "resource:org.acme.trading.Trader#trader1"
})
.then(function (results) {
   // do something

hope this helps. See further reference here -> https://hyperledger.github.io/composer//reference/query-language



来源:https://stackoverflow.com/questions/49395705/query-language-query-request-on-reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!