javascript - Sails.jswaterline: groupBy + count - Stack Overflow

Using sails.js (0.10.5):I can't figure out how to achieve a groupBycount using waterlinesails. W

Using sails.js (0.10.5):

I can't figure out how to achieve a groupBy/count using waterline/sails. What I would like to have is something like:

SELECT customer_id, COUNT('') FROM customer_data GROUP BY customer_id;
or
SELECT customer_id, SUM(1) FROM customer_data GROUP BY customer_id;

I wasn't able to achieve this using count nor sum (using a constant):

Customer.find({ groupBy:['customer_id'], count: true })
or
Customer.find({ groupBy:['customer_id'], sum: [1] })

Both will end in an error, the first "missing calculation" and the second "SQL syntax error". I can make a grouping using sum with an existing column (sum: ['id']) but that does not get me the count.

Am I using the API wrong?

Using sails.js (0.10.5):

I can't figure out how to achieve a groupBy/count using waterline/sails. What I would like to have is something like:

SELECT customer_id, COUNT('') FROM customer_data GROUP BY customer_id;
or
SELECT customer_id, SUM(1) FROM customer_data GROUP BY customer_id;

I wasn't able to achieve this using count nor sum (using a constant):

Customer.find({ groupBy:['customer_id'], count: true })
or
Customer.find({ groupBy:['customer_id'], sum: [1] })

Both will end in an error, the first "missing calculation" and the second "SQL syntax error". I can make a grouping using sum with an existing column (sum: ['id']) but that does not get me the count.

Am I using the API wrong?

Share Improve this question edited Nov 2, 2015 at 18:38 Joe Hill 3333 silver badges12 bronze badges asked Jan 9, 2015 at 5:27 tokoshtokosh 1,8365 gold badges21 silver badges40 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

please use Customer.query('SELECT customer_id, SUM(1) FROM customer_data GROUP BY customer_id', function(err,results){})

if you don't want use sql, you can like this to use Customer.find({groupBy:'customer_id'}).exec

ref: waterline-sequel select builder function

.query() is deprecated as of Sails v1.0, instead use .getDatastore().sendNativeQuery() (ref: https://sailsjs./documentation/reference/waterline-orm/models/query). There's still no way to do this with Waterline.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742309900a4419680.html

相关推荐

  • javascript - Sails.jswaterline: groupBy + count - Stack Overflow

    Using sails.js (0.10.5):I can't figure out how to achieve a groupBycount using waterlinesails. W

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信