简体   繁体   English

使用nodejs链码从hyperledger fabric v 1.4中的链码获取记录时如何设置偏移量和限制?

[英]how to set offset and limit while fetching records from chaincode in hyperledger fabric v 1.4 using nodejs chaincode?

I have more than 500 records in my blockchain network and i want to write a chaincode for the pagination on frontend.我的区块链网络中有 500 多条记录,我想为前端的分页编写链码。 I have used getQueryResultWithPagination and getStateByRangeWithPagination but my concern is that i want to fetch records starting from 90th to 100th means 10 records but not starting from beginning neither i want to fetch the whole record.我使用过getQueryResultWithPaginationgetStateByRangeWithPagination但我担心的是我想获取从 90 到 100 的记录意味着 10 条记录但不是从头开始,我也不想获取整个记录。 My chaincode is written in nodejs.我的链码是用 nodejs 编写的。 I'm stuck on this and would really appreciate the community to give me their valuable suggestions.我坚持这一点,非常感谢社区给我他们宝贵的建议。

Are you looking for directly jumping to a page if so, then its not possible. 如果您要直接跳转到页面,那是不可能的。 One drawback of the linked list style pagination is that you can't pre-compute the rows for a particular page from the page number and the rows per page. 链接列表样式分页的一个缺点是,您无法根据页码和每页的行数来预先计算特定页面的行。 Jumping to a specific page doesn't really work. 跳到特定页面实际上是行不通的。

Just see here for the reference: https://docs.couchdb.org/en/stable/ddocs/views/pagination.html 请参阅此处以获取参考: https : //docs.couchdb.org/en/stable/ddocs/views/pagination.html

getQueryResultWithPagination of course only works with CouchDB ... so when using the CouchDB query language you should be able to specify the skip parameter in your actual query. getQueryResultWithPagination当然仅适用于CouchDB ...因此,当使用CouchDB查询语言时,您应该能够在实际查询中指定skip参数。 Note that per the documentation, the limit parameter is not honored as the page size parameter is used: 请注意,根据文档,由于使用了页面大小参数,因此不建议使用limit参数:

If a pageSize is specified using the paginated query APIs (GetStateByRangeWithPagination(), GetStateByPartialCompositeKeyWithPagination(), and GetQueryResultWithPagination()), a set of results (bound by the pageSize) will be returned to the chaincode along with a bookmark. 如果使用分页查询API(GetStateByRangeWithPagination(),GetStateByPartialCompositeKeyWithPagination()和GetQueryResultWithPagination())指定了pageSize,则一组结果(由pageSize绑定)将与书签一起返回到链码。 The bookmark can be returned from chaincode to invoking clients, which can use the bookmark in a follow on query to receive the next “page” of results. 书签可以从链码返回给调用客户端,客户端可以在后续查询中使用书签来接收结果的下一个“页面”。

Of course to build a front-end client which pages through results, you need to pass both the pageSize and bookmark parameters to getQueryResultWithPagination and your chain code function will need to return the bookmark to the caller so that it can be passed in to fetch the next page of results. 当然,要构建一个可以浏览结果的前端客户端,您需要将pageSizebookmark参数都传递给getQueryResultWithPagination并且链代码函数需要将bookmark返回给调用者,以便可以将其传递来获取下一页结果。

如果有人有跳转分页的示例代码,请帮忙?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM