pouchdb-community / pouchdb-replication-stream

Replicate PouchDB/CouchDB databases with Node.js-style streams
Apache License 2.0
189 stars 58 forks source link

Enable passing of replication options #23

Closed conor-mac-aoidh closed 9 years ago

conor-mac-aoidh commented 9 years ago

This patch enables the user to pass custom replication options. This is useful for things like filtered replication.

nolanlawson commented 9 years ago

Thanks for the contribution! Just a few suggested changes:

Thanks!

conor-mac-aoidh commented 9 years ago

Well, in my case I need access to opts.view, opts.filter and opts.query_params. I don't see the point in restricting access to other options, maybe you could elaborate on why you think that's a good idea?

Ok, I'll add some tests and documentation later this evening.

nolanlawson commented 9 years ago

Well, I guess I had envisioned that this plugin would be a "simplified" version of replication, so I wouldn't carry all the baggage from replication itself. And I admit I'm not even familiar with the view or query_params options.

But I guess if you need specific options for some specific _replicate endpoint (are you using Couchbase/Cloudant/something else?), then yeah, the only way would be to pass all the options in. So I guess this is fine. :)

conor-mac-aoidh commented 9 years ago

Ok cool. I'm actually using this to build a replication stream from couchdb, to be bulk loaded into pouchdb on the frontend. We were having an issue where pouch would make /a ton/ of HTTP calls to fetch different revs from the remote db. As a solution, I added a route on our API which streams a filtered view of the db to the client in one request.

nolanlawson commented 9 years ago

Yup, that's exactly what I intended it for. Glad it's helping you out. :)

nolanlawson commented 9 years ago

I think this is the kick in the pants I needed to finally implement an Express endpoint for this thing. Was kinda hoping somebody else would, but nobody's risen to the occasion yet. Time to roll up the old sleeves...

conor-mac-aoidh commented 9 years ago

Hmm i have an express route for our own api, i could use a modified version of this and submit a pull request tomorrow if you like?

nolanlawson commented 9 years ago

Cool! I was thinking the express route should be its own separate plugin, though. Can you publish it as an npm module?

As for this module, expect it to get updated and published within the next few minutes; I'm just cleaning up your PR, adding tests and docs, etc. :)

nolanlawson commented 9 years ago

@conor-mac-aoidh check out #24

conor-mac-aoidh commented 9 years ago

Ok cool looks good. Im busy tonight but will have a proper look tomorrow afternoon!

I can do a separate module for the express route no problem, but its fairly minimal/basic atm - basically just a small function that calls this module. I could add passing of the replication parameters via the url/query string, which would make it more like couchdb - a HTTP API.

nolanlawson commented 9 years ago

Cool, gonna close this in favor of the other one. Try it out and let me know if it works for your use case.