cloudant / meteor-couchdb

Meteor database driver for CouchDB and Cloudant
Other
53 stars 7 forks source link

Added attachment API and documentation for the attachment API #17

Open ilfrich opened 8 years ago

ilfrich commented 8 years ago

Created functions to insert attachments, remove them and read them either as buffer or pipe them through to the response.

The documentation has been updated as well. Besides describing the additional attachment functions with examples how to use them, I also left a note on the update function, which will create a new revision of the document only containing the data provided to the update function. Existing data in the database will be overwritten by the new revision. For now this behaviour is described. In the future we could think about altering that behaviour and merging the existing document with the updates provided as default and only use the current behaviour (overwrite / replace) when specified by an option (or by calling a separate function replace(..))

mariobriggs commented 8 years ago

Hi Peter, thanks for these. Some thoughts whether you see no need for these methods on the client side ? Clients never subscribe to cursors that have attachments ? Can that be a future req ? Also one of the driving principles for meteor was same API on client and server, hence checking on above. (we anyhow give you u the DB object) Also the pipeAttachment with its response parameter, is hard to be generic API.

ilfrich commented 8 years ago

Afaik attachments are not delivered via the cursor and therefore no user subscribes to them, which means they're not available as binary in the client. The cursor only contains an _attachments field for each document owning attachments, which contains the attachment meta data (file name, size, mime type, etc.).

Having client-side functions to retrieve attachments sounds like an idea, although it would just be a replica of the example code in the README and add more convenience than functionality. The pipeAttachment function is there to make it easier for a developer to deliver attachments to the client via an explicit URL. I figured this is a common enough use-case to provide the functionality in the driver.