Get total count in Sails JS blueprint API
Asked Answered
C

1

3

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

Contrapuntist answered 5/10, 2015 at 7:37 Comment(0)
L
4

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 }
Louls answered 4/12, 2015 at 8:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.