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
Here's the format that I'm currently using to do the following from a model:
var Sample = bookshelf.Model.extend({
tableName: 'example',
count: function (cb) {
bookshelf.knex('example')
.count('id')
.then(function (count) {
cb(null, count)
})
.catch(function (err) {
cb(err)
})
}
})
Now, to count this table, simply call
new Sample().count(function(err, result) {
console.log(result)
});