Thursday 14 January 2016

How to thunkify Promises with Bookshelf?

Alright, the title may be a bit vague, but I couldn't come up with the right keywords to find this using Google. I am writing a piece of software where I use yield whenever necessary (well, not necessarily, but in this case it makes my code much easier to read and much cleaner). Anyway, libraries that don't support it, I thunkify by using thunkify (http://ift.tt/1QF0V3i). So far, so good.But Bookshelf has a different approach, because the functions are 'chained'. For example, say we have:User.where('id', 1).fetch({withRelated: ['posts.tags']}).then(function(user) {How do we thunkify this (if possible at all)? Do we use thunkify(User.where.fetch.then)?

Submitted January 14, 2016 at 10:50PM by itsYourDeveloper

No comments:

Post a Comment