bookshelf.js count method

后端 未结 6 804
星月不相逢
星月不相逢 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 01:45

    User.collection().query(function (qb) {
      qb.join('courses', 'users.id', 'courses.user_id');
      qb.groupBy('users.id');
      qb.select("users.*");
      qb.count('* as course_count');
      qb.orderBy("course_count", "desc");
    })
    

提交回复
热议问题