Query Language : Query request on reference

2019-05-20 08:10发布

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条回答
成全新的幸福
2楼-- · 2019-05-20 08:27

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

查看更多
登录 后发表回答