Created
November 23, 2011 23:11
-
-
Save pdaoust/1390208 to your computer and use it in GitHub Desktop.
augmenting Resourceful's Couchdb engine to allow insertion of new records without ID
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
Couchdb.prototype.post = function (doc, callback) { | |
return this.request('post', doc, function (e, res) { | |
if (e) return callback(e); | |
res.status = 201; | |
callback(null, res); | |
}); | |
}; | |
Couchdb.prototype.save = function (id, doc, callback) { | |
var args = Array.prototype.slice.call(arguments, 0); | |
var callback = args.pop(); | |
var doc = args.pop(); | |
// if there's an ID left in args after popping off the callback and | |
// the doc, then we need to PUT, otherwise create a new record thru POST | |
if (args.length) { | |
return this.put.apply(this, arguments); | |
} else { | |
return this.post.call(this, doc, callback); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment