Skip to content

Instantly share code, notes, and snippets.

@demisx
Last active January 25, 2016 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save demisx/d7d8b12d82adee47dccf to your computer and use it in GitHub Desktop.
Save demisx/d7d8b12d82adee47dccf to your computer and use it in GitHub Desktop.
BookshelfJS
  • There is no exposed reference from the model to bookshelf (e.g. can't do something like Ad.Bookshelf.knex). Need to require the bookshelf instance itself.

Getting count of models matching certain criteria

// select count(*) from "ads" where "classified_id" = 2'
Ad.where({ classified_id: 2 })
  .query() // <- returns QueryBuild instance
  .count()
  .then(function (count) {
    console.log('\n***', count);
  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment