-
Notifications
You must be signed in to change notification settings - Fork 568
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* master: 0.1.9 return undefined if model isn't fetched, fixes #21 allow an array to be passed to hasTimestamps, fixes #25 adding a plugin for node callback interface exec method, fixes #20 format on the first queries, fixes #26
- Loading branch information
Showing
7 changed files
with
140 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var Bookshelf = require('../bookshelf'); | ||
var _ = require('underscore'); | ||
|
||
// Used to optionally add `exec` support for those who prefer node-style callbacks. | ||
Bookshelf.wrapExec = function(target, method) { | ||
var targetMethod = target[method]; | ||
target[method] = function() { | ||
var result, args = arguments; | ||
var ctx = this; | ||
return { | ||
then: function(onFulfilled, onRejected) { | ||
result || (result = targetMethod.apply(ctx, args)); | ||
return result.then(onFulfilled, onRejected); | ||
}, | ||
exec: function(callback) { | ||
result || (result = targetMethod.apply(ctx, args)); | ||
return targetMethod.apply(ctx, args).then(function(resp) { | ||
callback(null, resp); | ||
}, function(err) { | ||
callback(err, null); | ||
}).then(null, function(err) { | ||
setTimeout(function() { throw err; }, 0); | ||
}); | ||
} | ||
}; | ||
}; | ||
}; | ||
|
||
_.each(['load', 'fetch', 'save', 'destroy'], function(method) { | ||
Bookshelf.wrapExec(Bookshelf.Model.prototype, method); | ||
}); | ||
|
||
_.each(['load', 'fetch'], function(method) { | ||
Bookshelf.wrapExec(Bookshelf.Collection.prototype, method); | ||
}); | ||
|
||
// Export the `Bookshelf` object. | ||
module.exports = Bookshelf; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters