Skip to content

Instantly share code, notes, and snippets.

@RWOverdijk
Created September 5, 2014 11:16
Show Gist options
  • Save RWOverdijk/f64d2c4e5bab4922e861 to your computer and use it in GitHub Desktop.
Save RWOverdijk/f64d2c4e5bab4922e861 to your computer and use it in GitHub Desktop.
Count blueprint as featured in http://blog.spoonx.nl/sails-js-count-blueprint/
var actionUtil = require('sails/lib/hooks/blueprints/actionUtil');
module.exports = function getCount (req, res) {
var Model = actionUtil.parseModel(req)
, criteria = actionUtil.parseCriteria(req);
Model.count(criteria, function(error, response) {
if (error) {
return res.serverError('database_error', error);
}
res.ok({count: response});
});
};
@artworkad
Copy link

👍 sweet, thank you!

@bigbn
Copy link

bigbn commented Apr 12, 2015

Can you please explain how to use it?
I'm using sails 0.10, and put this to api/blueprints folder of my project, i'we also make route as described in manual
'GET /count': {blueprint: 'count'},
but i dont get how to use it

@sergions80
Copy link

@bigbn you must specify the name of the domain / controller , for example:

If you have a Model Foo.js and Controller FooController.js

config/routes.js

'GET /foo/count': {blueprint: 'count'}

You can call http://localhost:1337/foo/count

It Works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment