查询语言:参考查询请求
Query Language : Query request on reference
按照教程,有查询
query selectCommoditiesByOwner {
description: "Select all commodities based on their owner"
statement:
SELECT org.acme.biznet.Commodity
WHERE (owner == _$owner)
}
但是没有一个例子解释如何请求它
对于参数owner
,我尝试使用节点变量owner
owner.toUri()
owner.getFullyQualifiedIdentifier()
"resource:" + owner.getFullyQualifiedIdentifier()
但没有任何效果
有人有工作示例吗?
有关如何 'request it' 的示例显示在查询教程的 REST API 部分 https://hyperledger.github.io/composer/tutorials/queries
如果您的意思是:使用 APIs 从交易处理器函数中请求它 - 在同一教程中有一个调用查询函数的示例,例如
/**
* 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
所以使用您的查询 - 您可能会做类似的事情:
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//reference/query-language
按照教程,有查询
query selectCommoditiesByOwner {
description: "Select all commodities based on their owner"
statement:
SELECT org.acme.biznet.Commodity
WHERE (owner == _$owner)
}
但是没有一个例子解释如何请求它
对于参数owner
,我尝试使用节点变量owner
owner.toUri()
owner.getFullyQualifiedIdentifier()
"resource:" + owner.getFullyQualifiedIdentifier()
但没有任何效果
有人有工作示例吗?
有关如何 'request it' 的示例显示在查询教程的 REST API 部分 https://hyperledger.github.io/composer/tutorials/queries
如果您的意思是:使用 APIs 从交易处理器函数中请求它 - 在同一教程中有一个调用查询函数的示例,例如
/**
* 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
所以使用您的查询 - 您可能会做类似的事情:
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//reference/query-language