pouchdb/mapreduce — pull request #184 by nolanlawson (2014-06-03 01:42:23+00:00)
Title: (#134) - allow persistence without ddocs

So here's an alternative idea for how we could handle the need for plugins to persist data without needing to save their own design doc.

Instead of breaking out persistence into a separate plugin (which would be very difficult, given all the hooks for deleting external DBs on `viewCleanup()` when their parent ddoc is deleted, as well as various other ddoc-specific code), I just punched a hole in the `query()` API, which allows you to set the option `{saveAs: 'foobar'}`, which will then persist whatever map/reduce function you give it, and it will be saved to an external DB called `-foobar` instead of `-mrview-`.

Best of all, you can pass a closure in as the map function, meaning that the search plugin can call lunr if it wants to, and the geo plugin could do whatever crazy transforms it wants to do before emitting. But in principles everything is still just map/reduce under the hood, and anything map/reduce can do, this function can do.

In the code, I also made it so you can either set `saveAs` on the map/reduce function or in the options, simply because it made the tests easier to write. But I also like it because it reduces the possibility of user error.

Thoughts?