Get total count in Sails JS blueprint API

风流意气都作罢 提交于 2020-01-06 03:23:13

问题


Can I use pagination or limit + skip that has a return "total page" or "total count" in sails js?


回答1:


I guess you mean when you use sails blueprint api methods? Unfortunately in current sails version (v0.11.3) you can't.

You must send another request for counting. That blueprint method also don't exist in current sails version, but you can use "sails-hook-blueprint-count" package which enable count method with filtering on all defined models.

"sails-hook-blueprint-count" package is available through npm repository (https://www.npmjs.com/package/sails-hook-blueprint-count) and you can install it with

npm install sails-hook-blueprint-count

command.

Then, when you lift sails app you can use routes like

GET /:model/count

or

GET /:model/count?where={:criteria}

:criteria is the same like in find where blueprint methods (http://sailsjs.org/documentation/reference/blueprint-api/find-where).

Response will be json with format

{ count : COUNT }


来源:https://stackoverflow.com/questions/32943436/get-total-count-in-sails-js-blueprint-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!