2017-08-28 37 views
1

我有一个具有ORDER BY子句的命名查询:ORDER BY在命名查询不工作

`query OrdersByRequesterSort { 
    description: "Select all orders by requester" 
    statement: 
     SELECT org.test.sample.Order 
      WHERE (requester == _$requesterParam) 
      ORDER BY [placeTimestamp DESC] 
}` 

这是我的查询,我在这里看到后patterened:

https://hyperledger.github.io/composer/reference/query-language.html

当我尝试执行此查询时出现以下错误:

` 
    { 
    "error": { 
    "statusCode": 500, 
    "name": "Error", 
    "message": "Error trying to query chaincode. Error: chaincode error (status: 500, message: Error: http: read on closed response body)", 
    "stack": "Error: Error trying to query chaincode. Error: chaincode error (status: 500, message: Error: http: read on closed response body)\n at channel.queryByChaincode.then.catch (/Users/bower/.nvm/versions/node/v6.3.0/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:779:34)" 
    } 
}` 

上午我做错了什么?这是否支持?

在此先感谢。

回答

1

对于我的网络,我命令查询从HistorianRecord通过时间戳返回:

query getAllHistorianRecords { 
    description: "getTradeRelatedHistorianRecords" 
    statement: 
    SELECT org.hyperledger.composer.system.HistorianRecord 
     WHERE (transactionTimestamp > '0000-01-01T00:00:00.000Z') 
     ORDER BY [transactionTimestamp ASC] 
} 

为了使这个ORDER BY发言工作,我不得不创建一个索引CouchDB的。如果你使用这些脚本来创建你的结构,你的数据库应该在http://localhost:5984/_utils/#database/composerchannel/_all_docs

curl -X POST --header 'Content-Type: application/json' --header 
'Accept: application/json' -d ' 
{ 
    "index": { 
    "fields": [ 
     { 
     "data.transactionTimestamp": "asc" 
     } 
    ] 
    }, 
    "type": "json" 
}' 'http://localhost:5984/composerchannel/_index' 

这卷曲将创建一个索引,查询可用于启用ORDER BY