You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Geoffrey Cox <re...@gmail.com> on 2017/07/19 14:31:13 UTC

Don’t Just Relax; Slouch: A JS Client for CouchDB that Does the Heavy Lifting

Hi,

We just released, Slouch, another JS client for CouchDB. On the surface, it
may seem like we have reinvented the wheel as there is already nano and
nano is pretty awesome. However, Slouch approaches things from a slightly
different perspective and has allowed us to greatly simply our application
layer.

You can read more about it on medium.
<https://medium.com/@redgeoff/dont-just-relax-slouch-a-js-client-for-couchdb-that-does-the-heavy-lifting-d8232eba8e2c>

Or, jump straight the repo. <https://github.com/redgeoff/slouch>

I welcome any feedback and hope this helps others.

Thanks.

Geoff

Re: Don’t Just Relax; Slouch: A JS Client for CouchDB that Does the Heavy Lifting

Posted by Geoffrey Cox <re...@gmail.com>.
Thanks, Garren!

On Mon, Jul 24, 2017, 01:57 Garren Smith <ga...@apache.org> wrote:

> This is really cool. Nice work Geoff.
>
> On Thu, Jul 20, 2017 at 5:23 PM, Geoffrey Cox <re...@gmail.com> wrote:
>
> > These are some great points, Sean, and the answer is that slouch doesn't
> > take either of those away.
> >
> > You can use iterator.abort() to stop the iteration, e.g.
> > https://github.com/redgeoff/slouch/wiki/Don't-just-relax.-
> > Slouch!#example-4---continuously-process-all-changes-to-a-db
> >
> > Also, you can get a node stream from the iterator with
> iterator.toStream().
> > (For more info see
> > https://github.com/redgeoff/quelle/blob/master/scripts/
> > stream-iterator.js#L149--sorry,
> > documentation is still coming)
> >
> > In the end, this new pattern may not be to your liking, but we've found
> it
> > to greatly simplify our code. And, you still have options to also keep
> with
> > existing conventions.
> >
> > On Thu, Jul 20, 2017 at 7:42 AM Sean Lang <sl...@gmail.com> wrote:
> >
> > > Except, I can't just pass a `.each` function to one of the hundreds of
> > > existing stream related utilities that have been published on npm. I
> > can't
> > > use flow control or destroy the iterator once I've read enough data,
> > unlike
> > > a stream.
> > >
> > > On Thu, Jul 20, 2017, 09:33 Geoffrey Cox <re...@gmail.com> wrote:
> > >
> > > > Hi Sean,
> > > >
> > > > Sure, you could use a stream, but you'd probably end up writing a
> bunch
> > > of
> > > > code to do what you can do in just a few lines with slouch.
> > > >
> > > > For example, here is an example of using the _all_docs API in nano:
> > > > https://github.com/redgeoff/slouch/blob/master/examples/nano-all.js
> > > >
> > > > And here is a similar example using slouch:
> > > > https://github.com/redgeoff/slouch/blob/master/examples/all.js
> > > >
> > > > Slouch really gets cool when you start using a Throttler to provide
> > some
> > > > concurrency without totally slamming your CPU:
> > > >
> > > >
> > > https://github.com/redgeoff/slouch/wiki/Don%27t-just-
> > relax.-Slouch%21#example-2---process-a-max-of-5-docs-concurrently
> > > >
> > > >
> > > > Geoff
> > > >
> > > >
> > > >
> > > > On Wed, Jul 19, 2017 at 10:26 PM Sean Lang <sl...@gmail.com>
> wrote:
> > > >
> > > > > `.each` is kinda weird for iteration. Can't you just return a
> > standard
> > > > > Node.js stream?
> > > > >
> > > > > On Wed, Jul 19, 2017, 09:31 Geoffrey Cox <re...@gmail.com>
> wrote:
> > > > >
> > > > > > Hi,
> > > > > >
> > > > > > We just released, Slouch, another JS client for CouchDB. On the
> > > > surface,
> > > > > it
> > > > > > may seem like we have reinvented the wheel as there is already
> nano
> > > and
> > > > > > nano is pretty awesome. However, Slouch approaches things from a
> > > > slightly
> > > > > > different perspective and has allowed us to greatly simply our
> > > > > application
> > > > > > layer.
> > > > > >
> > > > > > You can read more about it on medium.
> > > > > > <
> > > > > >
> > > > >
> > > >
> > > https://medium.com/@redgeoff/dont-just-relax-slouch-a-js-
> > client-for-couchdb-that-does-the-heavy-lifting-d8232eba8e2c
> > > > > > >
> > > > > >
> > > > > > Or, jump straight the repo. <https://github.com/redgeoff/slouch>
> > > > > >
> > > > > > I welcome any feedback and hope this helps others.
> > > > > >
> > > > > > Thanks.
> > > > > >
> > > > > > Geoff
> > > > > >
> > > > >
> > > >
> > >
> >
>

Re: Don’t Just Relax; Slouch: A JS Client for CouchDB that Does the Heavy Lifting

Posted by Garren Smith <ga...@apache.org>.
This is really cool. Nice work Geoff.

On Thu, Jul 20, 2017 at 5:23 PM, Geoffrey Cox <re...@gmail.com> wrote:

> These are some great points, Sean, and the answer is that slouch doesn't
> take either of those away.
>
> You can use iterator.abort() to stop the iteration, e.g.
> https://github.com/redgeoff/slouch/wiki/Don't-just-relax.-
> Slouch!#example-4---continuously-process-all-changes-to-a-db
>
> Also, you can get a node stream from the iterator with iterator.toStream().
> (For more info see
> https://github.com/redgeoff/quelle/blob/master/scripts/
> stream-iterator.js#L149--sorry,
> documentation is still coming)
>
> In the end, this new pattern may not be to your liking, but we've found it
> to greatly simplify our code. And, you still have options to also keep with
> existing conventions.
>
> On Thu, Jul 20, 2017 at 7:42 AM Sean Lang <sl...@gmail.com> wrote:
>
> > Except, I can't just pass a `.each` function to one of the hundreds of
> > existing stream related utilities that have been published on npm. I
> can't
> > use flow control or destroy the iterator once I've read enough data,
> unlike
> > a stream.
> >
> > On Thu, Jul 20, 2017, 09:33 Geoffrey Cox <re...@gmail.com> wrote:
> >
> > > Hi Sean,
> > >
> > > Sure, you could use a stream, but you'd probably end up writing a bunch
> > of
> > > code to do what you can do in just a few lines with slouch.
> > >
> > > For example, here is an example of using the _all_docs API in nano:
> > > https://github.com/redgeoff/slouch/blob/master/examples/nano-all.js
> > >
> > > And here is a similar example using slouch:
> > > https://github.com/redgeoff/slouch/blob/master/examples/all.js
> > >
> > > Slouch really gets cool when you start using a Throttler to provide
> some
> > > concurrency without totally slamming your CPU:
> > >
> > >
> > https://github.com/redgeoff/slouch/wiki/Don%27t-just-
> relax.-Slouch%21#example-2---process-a-max-of-5-docs-concurrently
> > >
> > >
> > > Geoff
> > >
> > >
> > >
> > > On Wed, Jul 19, 2017 at 10:26 PM Sean Lang <sl...@gmail.com> wrote:
> > >
> > > > `.each` is kinda weird for iteration. Can't you just return a
> standard
> > > > Node.js stream?
> > > >
> > > > On Wed, Jul 19, 2017, 09:31 Geoffrey Cox <re...@gmail.com> wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > > We just released, Slouch, another JS client for CouchDB. On the
> > > surface,
> > > > it
> > > > > may seem like we have reinvented the wheel as there is already nano
> > and
> > > > > nano is pretty awesome. However, Slouch approaches things from a
> > > slightly
> > > > > different perspective and has allowed us to greatly simply our
> > > > application
> > > > > layer.
> > > > >
> > > > > You can read more about it on medium.
> > > > > <
> > > > >
> > > >
> > >
> > https://medium.com/@redgeoff/dont-just-relax-slouch-a-js-
> client-for-couchdb-that-does-the-heavy-lifting-d8232eba8e2c
> > > > > >
> > > > >
> > > > > Or, jump straight the repo. <https://github.com/redgeoff/slouch>
> > > > >
> > > > > I welcome any feedback and hope this helps others.
> > > > >
> > > > > Thanks.
> > > > >
> > > > > Geoff
> > > > >
> > > >
> > >
> >
>

Re: Don’t Just Relax; Slouch: A JS Client for CouchDB that Does the Heavy Lifting

Posted by Geoffrey Cox <re...@gmail.com>.
These are some great points, Sean, and the answer is that slouch doesn't
take either of those away.

You can use iterator.abort() to stop the iteration, e.g.
https://github.com/redgeoff/slouch/wiki/Don't-just-relax.-Slouch!#example-4---continuously-process-all-changes-to-a-db

Also, you can get a node stream from the iterator with iterator.toStream().
(For more info see
https://github.com/redgeoff/quelle/blob/master/scripts/stream-iterator.js#L149--sorry,
documentation is still coming)

In the end, this new pattern may not be to your liking, but we've found it
to greatly simplify our code. And, you still have options to also keep with
existing conventions.

On Thu, Jul 20, 2017 at 7:42 AM Sean Lang <sl...@gmail.com> wrote:

> Except, I can't just pass a `.each` function to one of the hundreds of
> existing stream related utilities that have been published on npm. I can't
> use flow control or destroy the iterator once I've read enough data, unlike
> a stream.
>
> On Thu, Jul 20, 2017, 09:33 Geoffrey Cox <re...@gmail.com> wrote:
>
> > Hi Sean,
> >
> > Sure, you could use a stream, but you'd probably end up writing a bunch
> of
> > code to do what you can do in just a few lines with slouch.
> >
> > For example, here is an example of using the _all_docs API in nano:
> > https://github.com/redgeoff/slouch/blob/master/examples/nano-all.js
> >
> > And here is a similar example using slouch:
> > https://github.com/redgeoff/slouch/blob/master/examples/all.js
> >
> > Slouch really gets cool when you start using a Throttler to provide some
> > concurrency without totally slamming your CPU:
> >
> >
> https://github.com/redgeoff/slouch/wiki/Don%27t-just-relax.-Slouch%21#example-2---process-a-max-of-5-docs-concurrently
> >
> >
> > Geoff
> >
> >
> >
> > On Wed, Jul 19, 2017 at 10:26 PM Sean Lang <sl...@gmail.com> wrote:
> >
> > > `.each` is kinda weird for iteration. Can't you just return a standard
> > > Node.js stream?
> > >
> > > On Wed, Jul 19, 2017, 09:31 Geoffrey Cox <re...@gmail.com> wrote:
> > >
> > > > Hi,
> > > >
> > > > We just released, Slouch, another JS client for CouchDB. On the
> > surface,
> > > it
> > > > may seem like we have reinvented the wheel as there is already nano
> and
> > > > nano is pretty awesome. However, Slouch approaches things from a
> > slightly
> > > > different perspective and has allowed us to greatly simply our
> > > application
> > > > layer.
> > > >
> > > > You can read more about it on medium.
> > > > <
> > > >
> > >
> >
> https://medium.com/@redgeoff/dont-just-relax-slouch-a-js-client-for-couchdb-that-does-the-heavy-lifting-d8232eba8e2c
> > > > >
> > > >
> > > > Or, jump straight the repo. <https://github.com/redgeoff/slouch>
> > > >
> > > > I welcome any feedback and hope this helps others.
> > > >
> > > > Thanks.
> > > >
> > > > Geoff
> > > >
> > >
> >
>

Re: Don’t Just Relax; Slouch: A JS Client for CouchDB that Does the Heavy Lifting

Posted by Sean Lang <sl...@gmail.com>.
Except, I can't just pass a `.each` function to one of the hundreds of
existing stream related utilities that have been published on npm. I can't
use flow control or destroy the iterator once I've read enough data, unlike
a stream.

On Thu, Jul 20, 2017, 09:33 Geoffrey Cox <re...@gmail.com> wrote:

> Hi Sean,
>
> Sure, you could use a stream, but you'd probably end up writing a bunch of
> code to do what you can do in just a few lines with slouch.
>
> For example, here is an example of using the _all_docs API in nano:
> https://github.com/redgeoff/slouch/blob/master/examples/nano-all.js
>
> And here is a similar example using slouch:
> https://github.com/redgeoff/slouch/blob/master/examples/all.js
>
> Slouch really gets cool when you start using a Throttler to provide some
> concurrency without totally slamming your CPU:
>
> https://github.com/redgeoff/slouch/wiki/Don%27t-just-relax.-Slouch%21#example-2---process-a-max-of-5-docs-concurrently
>
>
> Geoff
>
>
>
> On Wed, Jul 19, 2017 at 10:26 PM Sean Lang <sl...@gmail.com> wrote:
>
> > `.each` is kinda weird for iteration. Can't you just return a standard
> > Node.js stream?
> >
> > On Wed, Jul 19, 2017, 09:31 Geoffrey Cox <re...@gmail.com> wrote:
> >
> > > Hi,
> > >
> > > We just released, Slouch, another JS client for CouchDB. On the
> surface,
> > it
> > > may seem like we have reinvented the wheel as there is already nano and
> > > nano is pretty awesome. However, Slouch approaches things from a
> slightly
> > > different perspective and has allowed us to greatly simply our
> > application
> > > layer.
> > >
> > > You can read more about it on medium.
> > > <
> > >
> >
> https://medium.com/@redgeoff/dont-just-relax-slouch-a-js-client-for-couchdb-that-does-the-heavy-lifting-d8232eba8e2c
> > > >
> > >
> > > Or, jump straight the repo. <https://github.com/redgeoff/slouch>
> > >
> > > I welcome any feedback and hope this helps others.
> > >
> > > Thanks.
> > >
> > > Geoff
> > >
> >
>

Re: Don’t Just Relax; Slouch: A JS Client for CouchDB that Does the Heavy Lifting

Posted by Geoffrey Cox <re...@gmail.com>.
Hi Sean,

Sure, you could use a stream, but you'd probably end up writing a bunch of
code to do what you can do in just a few lines with slouch.

For example, here is an example of using the _all_docs API in nano:
https://github.com/redgeoff/slouch/blob/master/examples/nano-all.js

And here is a similar example using slouch:
https://github.com/redgeoff/slouch/blob/master/examples/all.js

Slouch really gets cool when you start using a Throttler to provide some
concurrency without totally slamming your CPU:
https://github.com/redgeoff/slouch/wiki/Don%27t-just-relax.-Slouch%21#example-2---process-a-max-of-5-docs-concurrently


Geoff



On Wed, Jul 19, 2017 at 10:26 PM Sean Lang <sl...@gmail.com> wrote:

> `.each` is kinda weird for iteration. Can't you just return a standard
> Node.js stream?
>
> On Wed, Jul 19, 2017, 09:31 Geoffrey Cox <re...@gmail.com> wrote:
>
> > Hi,
> >
> > We just released, Slouch, another JS client for CouchDB. On the surface,
> it
> > may seem like we have reinvented the wheel as there is already nano and
> > nano is pretty awesome. However, Slouch approaches things from a slightly
> > different perspective and has allowed us to greatly simply our
> application
> > layer.
> >
> > You can read more about it on medium.
> > <
> >
> https://medium.com/@redgeoff/dont-just-relax-slouch-a-js-client-for-couchdb-that-does-the-heavy-lifting-d8232eba8e2c
> > >
> >
> > Or, jump straight the repo. <https://github.com/redgeoff/slouch>
> >
> > I welcome any feedback and hope this helps others.
> >
> > Thanks.
> >
> > Geoff
> >
>

Re: Don’t Just Relax; Slouch: A JS Client for CouchDB that Does the Heavy Lifting

Posted by Sean Lang <sl...@gmail.com>.
`.each` is kinda weird for iteration. Can't you just return a standard
Node.js stream?

On Wed, Jul 19, 2017, 09:31 Geoffrey Cox <re...@gmail.com> wrote:

> Hi,
>
> We just released, Slouch, another JS client for CouchDB. On the surface, it
> may seem like we have reinvented the wheel as there is already nano and
> nano is pretty awesome. However, Slouch approaches things from a slightly
> different perspective and has allowed us to greatly simply our application
> layer.
>
> You can read more about it on medium.
> <
> https://medium.com/@redgeoff/dont-just-relax-slouch-a-js-client-for-couchdb-that-does-the-heavy-lifting-d8232eba8e2c
> >
>
> Or, jump straight the repo. <https://github.com/redgeoff/slouch>
>
> I welcome any feedback and hope this helps others.
>
> Thanks.
>
> Geoff
>