Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

readStream options are sticky #6

Closed
chesles opened this issue Oct 17, 2012 · 3 comments
Closed

readStream options are sticky #6

chesles opened this issue Oct 17, 2012 · 3 comments

Comments

@chesles
Copy link

chesles commented Oct 17, 2012

When I get a readStream({reverse: true}), followed by a plain readStream(), I get the documents out in reverse order again, unless I specify reverse: false. start and end behave similarly, the last value for each option acting as the default value for the next call.

Example:

> db.readStream().on('data', console.log)
{ key: '0', value: "blah" }
{ key: '1', value: "foo" }
{ key: '2', value: "bar" }
{ key: '3', value: "..." }

# ok, reverse the stream
> db.readStream({reverse: true}).on('data', console.log)
{ key: '3', value: "..." }
{ key: '2', value: "bar" }
{ key: '1', value: "foo" }
{ key: '0', value: "blah" }

# stream is still reversed
> db.readStream().on('data', console.log)
{ key: '3', value: "..." }
{ key: '2', value: "bar" }
{ key: '1', value: "foo" }
{ key: '0', value: "blah" }

# back to normal with reverse: false
> db.readStream({reverse: false}).on('data', console.log)
{ key: '0', value: "blah" }
{ key: '1', value: "foo" }
{ key: '2', value: "bar" }
{ key: '3', value: "..." }
@tilgovi
Copy link

tilgovi commented Oct 17, 2012

It looks like the problem is in this line: /~https://github.com/rvagg/node-levelup/blob/master/lib/levelup.js#L209

I think it should read:

options = extend(extend({}, this._options), typeof options == 'object' ? options : {})

In other words, properties from this._options should be copied into a fresh object and that object should be extended by the options passed as an argument to db.readStrem. Currently, the code is extending this._options each time.

@rvagg
Copy link
Member

rvagg commented Oct 17, 2012

Thanks for picking this up @chesles, nice find! I have a unit test for this now and it's fixed in 0.1.1.

I'd be happy to hear about any issues you're having with the lib in pouchdb; my uses for it currently aren't as extensive as what you're going to put it through so I'm sure you'll pick up more things that I haven't run in to. I'm also happy to consider any functionality you think belongs at this level rather than in pouchdb.

@rvagg rvagg closed this as completed Oct 17, 2012
@chesles
Copy link
Author

chesles commented Oct 18, 2012

Thanks @rvagg! I do have a few other small issues I'll open as soon as I have time. Thanks for a great library :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants