Skip to content

Commit

Permalink
Optional attachments in db.getDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
0xDB committed May 18, 2012
1 parent da7941a commit ea84eb8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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)

Expand Down
27 changes: 24 additions & 3 deletions lib/couchdb.js
Expand Up @@ -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);
};

Expand Down

0 comments on commit ea84eb8

Please sign in to comment.