当CouchDB查询返回大型结果集时,可以使用一系列API,这些API可以通过调用链代码来对结果列表进行分页。 分页提供了一种机制,通过指定页面大小和起始点来划分结果集——一个指示结果集开始位置的书签。 客户端应用程序迭代地调用执行查询的链代码,直到不再返回结果。
我们将使用Marbles示例函数queryMarblesWithPagination来演示如何在链代码和客户端应用程序中实现分页。
https://github.com/hyperledger/fabric-samples/blob/master/chaincode/marbles02/go/marbles_chaincode.go
queryMarblesWithPagination –具有分页的临时丰富查询的示例。 这是一个查询,其中(选择器)字符串可以传递到类似于上面示例的函数中。 在这种情况下,查询还包括pageSize以及书签。
为了展示分页,需要更多数据。 此示例假定您已从上方添加了marble1。 在对等容器中运行以下命令以创建“tom”拥有的四个大理石,以创建由“tom”拥有的总共五个大理石:
peer chaincode invoke -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n marbles -c '{"Args":["initMarble","marble2","yellow","35","tom"]}'
peer chaincode invoke -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n marbles -c '{"Args":["initMarble","marble3","green","20","tom"]}'
peer chaincode invoke -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/examp