bookshelf.js count method

后端 未结 6 810
星月不相逢
星月不相逢 2021-02-14 01:20

I was searching high and low to find how to do basic counting (like SELECT COUNT(something) FROM table) with Bookshelf.js, but to no avail. Is there anything I\'m missing? Or is

6条回答
  •  离开以前
    2021-02-14 02:01

    Here is a really simple solution just use Bookshelf.knex.raw('count(id) as count')

    ReactionsDb
        .query(function(qb) {
          qb.groupBy('reaction_type');
        })
        .fetchAll({columns: ['reaction_type', Bookshelf.knex.raw('count(id) as count')]});
    

提交回复
热议问题