ORDER BY在命名查询中不起作用 [英] ORDER BY not working in named query

查看:92
本文介绍了ORDER BY在命名查询中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有ORDER BY子句的命名查询:

I've got a named query that has an ORDER BY clause:

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

我在这里看到的查询后对它进行了编程:

which I patterened after a query that I saw here:

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

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

I'm getting the following error when I attempt to execute this query:

`
    {
  "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)"
  }
}`

我做错什么了吗?支持吗?

Am I doing something wrong? Is this supported?

谢谢.

推荐答案

对于我的网络,我按时间戳排序从HistorianRecord返回的查询:

For my network, I order the query returned from HistorianRecord by the timestamp:

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.

To make this ORDER BY statement work I had to create an index in CouchDB. If you used the scripts to create your fabric your database should be at 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'

此curl将创建一个索引,该查询可用于启用ORDER BY

This curl will create an index that the query can use to enable ORDER BY

这篇关于ORDER BY在命名查询中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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