bookshelf.js count method

后端 未结 6 819
星月不相逢
星月不相逢 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:42

    For now it's a manual query... e.g:

    bookshelf.knex(tableName).count('columnName').then(...
    

    Long story as to why that's the case, but it's mainly because of a few complexities around counts in relations, I don't want to hack a half working one on there just for the sake of having it there for the time being... the ultimate solution is going to be to have:

    model.query().count(column).then(...
    

    But currently that mutates the knex query builder instance, so doesn't quite work. I've been working on a big refactor of knex and I'm looking to get this implemented in the near future.

提交回复
热议问题