Working with Bookshelf.

Bookshelf is an awesome ORM.
But the documentation is lacking in examples like non other.

I’m new to the Node world and almost all of these docs have the assumptions you know everything about Node outside of just this small function that the library provides.

First, since node is async, Bookshelf is also. Bookshelf uses promises (while others use callbacks).
This is great for a website but not great of a utility tool since you are dependent on the data being there before the next step.
So you have to wait for the ‘.then’ or the ‘fetched’ event (still figuring out how to use that…)

Example Code:

var newUser = {
'name': 'Joe',
'email': ''

new self.models.User(newUser).save().then(function (model) {

That looks nice and all, BUT, now you want to send an email, well you have to do that inside of the .save or have some kind of callback.
A way around this is emit another event.

Dealing with .fetchAll and collection.fetch

Getting Started with Bookshelf.js

Continue reading Working with Bookshelf.