2017-08-28 36 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