Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

getDoc: added '?attachments=' #39

Merged
merged 1 commit into from almost 2 years ago

3 participants

Daniel Mike Coolin Georg Dresler
Daniel
0xDB commented May 18, 2012

Hi!

I added support for '?attachments=' to getDoc.

I realize adding an options-object as parameter would be better than two optional parameters, but it would break programs already using the function with the rev parameter.

I would also like to add the option for '?atts_since=' some time soon, but that would definitely require an options-parameter of some sort.

Also, I'm new to Javascript and GitHub. If i did something in the wrong way, constructive criticism would be very helpful :)

Kind Regards,
Daniel

Mike Coolin
Collaborator
mcoolin commented May 18, 2012

Let me take a look and figure out git. I do have a merge option!

Mike Coolin mcoolin merged commit 56a1a30 into from May 18, 2012
Mike Coolin mcoolin closed this May 18, 2012
Georg Dresler
ge-org commented May 21, 2012

Not only ?atts_since= would be cool, but also ?revs_info= and ?revs=
http://wiki.apache.org/couchdb/HTTP_Document_API#Special_Fields

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

May 18, 2012
Daniel Optional attachments in db.getDoc ea84eb8
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 26 additions and 5 deletions. Show diff stats Hide diff stats

  1. 4  README.md
  2. 27  lib/couchdb.js
4  README.md
Source Rendered
@@ -197,9 +197,9 @@ Wrapper for [PUT /db-name](http://wiki.apache.org/couchdb/HTTP_database_API#PUT_
197 197
 
198 198
 Wrapper for [DELETE /db-name](http://wiki.apache.org/couchdb/HTTP_database_API#DELETE).
199 199
 
200  
-### db.getDoc(id, [rev])
  200
+### db.getDoc(id, [rev], [attachments])
201 201
 
202  
-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.
  202
+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.
203 203
 
204 204
 ### db.saveDoc(id, doc)
205 205
 
27  lib/couchdb.js
@@ -377,18 +377,39 @@ Db.prototype.remove = function(cb) {
377 377
   return this.request('DELETE', '', cb);
378 378
 };
379 379
 
380  
-Db.prototype.getDoc = function(id, rev, cb) {
  380
+Db.prototype.getDoc = function(id, rev, attachments, cb) {
381 381
   var request = {
382 382
     path: '/'+id
383 383
   };
384  
-  if (!cb && typeof rev === 'function') {
  384
+  
  385
+  if (!cb && !attachments && typeof rev === 'function') {
385 386
     cb = rev;
  387
+    rev = undefined;
  388
+  } else if (!cb && typeof attachments === 'function') {
  389
+    cb = attachments;
  390
+    if (typeof rev === 'boolean') {
  391
+      attachments = rev;
  392
+      rev = undefined;
  393
+    } else {
  394
+      attachments = undefined;
  395
+    }
386 396
   }
387  
-  else {
  397
+  
  398
+  if (rev) {
388 399
     request.query = {
389 400
       'rev': rev
390 401
     };
391 402
   }
  403
+  if (attachments) {
  404
+    if(!request.query) {
  405
+      request.query = {};
  406
+    }
  407
+    request.query.attachments = attachments;
  408
+    request.headers = {
  409
+      Accept: "application/json"
  410
+    }
  411
+  }
  412
+  
392 413
   return this.request(request, cb);
393 414
 };
394 415
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.