couchbaselabs/TouchDB-iOS — Issue #2: Attachments
Author: snej
Created: 2011-12-18 16:50:44+00:00
State: open

The most glaring missing CouchDB feature is document attachments. This is really important.

It's actually partly implemented already. What exists is:

* TDBlobStore, a very simple content-addressable store. It saves arbitrary data blobs as files in a directory, named according to their SHA-1 digest, and can retrieve a blob given its digest. This is where the actual attachment data will live.
* An "attachments" table in the SQLite database schema. Each row contains a sequence ID (of the revision that owns this attachment), a filename, and a key into the blob store (i.e. the attachment's SHA-1 digest.)
* TDDatabase methods to add a named attachment blob to a revision, to fetch a blob from a revision given its filename, and to garbage-collect the blob store by removing all attachments that aren't referred to by any available revision.

The remaining work is to hook those TDDatabase methods up to the higher levels:

* TDRouter needs to interpret the _attachments property of a JSON document being stored, and add attachments to the revision.
* It also needs to detect URLs that refer to a revision of a document and return the raw revision body in the response.
* The replicator code needs to send and receive attachments along with revisions (being careful not to transmit attachments that are already stored at the target database.)