Skip to content
Browse files

Merge pull request #39 from 0xDB/master

getDoc: added '?attachments='
  • Loading branch information...
2 parents da7941a + ea84eb8 commit 56a1a3043a68b1f614bf33e51db6d5dbc6190455 @mcoolin mcoolin committed May 18, 2012
Showing with 26 additions and 5 deletions.
  1. +2 −2 README.md
  2. +24 −3 lib/couchdb.js
View
4 README.md
@@ -197,9 +197,9 @@ Wrapper for [PUT /db-name](http://wiki.apache.org/couchdb/HTTP_database_API#PUT_
Wrapper for [DELETE /db-name](http://wiki.apache.org/couchdb/HTTP_database_API#DELETE).
-### db.getDoc(id, [rev])
+### db.getDoc(id, [rev], [attachments])
-Wrapper for [GET /db-name/doc-id\[?rev=\]](http://wiki.apache.org/couchdb/HTTP_Document_API#GET). Fetches a document with a given `id` and optional `rev` from the database.
+Wrapper for [GET /db-name/doc-id\[?rev=\]\[&attachments=\]](http://wiki.apache.org/couchdb/HTTP_Document_API#GET). Fetches a document with a given `id` and optional `rev` and/or `attachments` from the database.
### db.saveDoc(id, doc)
View
27 lib/couchdb.js
@@ -377,18 +377,39 @@ Db.prototype.remove = function(cb) {
return this.request('DELETE', '', cb);
};
-Db.prototype.getDoc = function(id, rev, cb) {
+Db.prototype.getDoc = function(id, rev, attachments, cb) {
var request = {
path: '/'+id
};
- if (!cb && typeof rev === 'function') {
+
+ if (!cb && !attachments && typeof rev === 'function') {
cb = rev;
+ rev = undefined;
+ } else if (!cb && typeof attachments === 'function') {
+ cb = attachments;
+ if (typeof rev === 'boolean') {
+ attachments = rev;
+ rev = undefined;
+ } else {
+ attachments = undefined;
+ }
}
- else {
+
+ if (rev) {
request.query = {
'rev': rev
};
}
+ if (attachments) {
+ if(!request.query) {
+ request.query = {};
+ }
+ request.query.attachments = attachments;
+ request.headers = {
+ Accept: "application/json"
+ }
+ }
+
return this.request(request, cb);
};

0 comments on commit 56a1a30

Please sign in to comment.
Something went wrong with that request. Please try again.