查询语言:参考查询请求 [英] Query Language : Query request on reference

查看:32
本文介绍了查询语言:参考查询请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在教程之后,有查询

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

对于参数owner,我尝试使用节点变量owner

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

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

但是没有任何作用

有人有一个可行的例子吗?

Does somebody has a working example?

推荐答案

查询"示例的示例显示在查询"教程的"REST API"部分中.

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

如果您的意思是:使用API​​从事务处理器函数中进行请求-同一教程中有一个示例,例如调用Query函数.

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

希望这会有所帮助.在此处查看更多参考-> https://hyperledger.github.io/composer//参考/查询语言

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

这篇关于查询语言:参考查询请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆