daleharvey/pouchdb — pull request #317 by chesles (2012-12-30 03:18:28+00:00)
Title: 296 generic adapter

I'm just gonna leave this here:

- in-memory adapter working under node.js
- generic adapter working under node.js

The generic adapter has 1 dependency on node: it uses the `crypto` module to get the md5 digest for attachments. This dependency should be easy to remove, I just haven't gotten to it yet.

The in-memory adapter _should_ work in the browser out of the box, once the generic adapter is working.

Any comments on the generic API are welcome. As it is now, to add an adapter you need to implement the following methods:

- `id` - return the name/id of the database
- `type` - return the storage type
- `init` - initialize/open stores
- `getMetadata` - read from the `metadata` store
- `getBulkMetadata` - read a bunch of metadata
- `writeMetadata` - write to the `metadata` store
- `getUpdateSeq` - return the update sequence (the highest seq passed to `writeSeq` so far, or the stored value)
- `getSequence` - read from the `by-sequence` store
- `getBulkSequence` - read a bunch from the `by-sequence` store
- `writeSequence` - write to the `by-sequence` store
- `getAttachment` - read from `attachment` store
- `writeAttachment` - write to the `attachment` store

Any comments/suggestions/improvements on this API are welcome. One thing I might like to do is have the "Bulk" methods return a stream, so for example in the leveldb adapter we could take advantage of the streaming api provided by levelup. I'm not sure how that would impact other adapters' implementations though. Also, thoughts on re-using node's Stream code in the browsers via browserify?