1602/jugglingdb — pull request #86 by Tuskan360 (2012-05-18 15:20:59+00:00)
Title: Allow promises to be used with Q

I really think we should avoid having this library force people either into promise methodology or into callback methodology. In order to do this, I propose wrapping all functions that take a callback as their last argument, and use a node style callback (`callback(err,result)`) with a function called `async`. This async function can detect the presence of Q and then provide promises if Q is present and no callback was supplied. See `lib/utils.js` for the location of that function.

I did try doing this as a separate library (https://github.com/jepso/jugglingdbq) but it ends up being a lot of complex, brittle code that relies heavily on un-documented behaviour. It is however, extemely simple to add this behaviour to the library by editing it in this way.

I have yet to implement promises for belongsTo relationships as these are a little more subtle (there is a synchronous version of that function which returns the foreign key).