-
-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exclusive vs inclusive start/end min/max #118
Comments
ftr, my thoughts on this:
I'd like to hear from others who are actually making heavy use of ranges in production to see if there are actual pain points here to be addressed? |
when you use some high character as the end point (like '\xff') you need to be sure that it is not actually a part of a key. At least, it's not a part of a key that you will want to retrive as part of a range. I'm having a little difficulty understanding your second bullet point, |
just thinking through edge-cases, don't want |
very good point! currently, in level-sublevel, |
Hmm, I've been thinking about this, and my feeling is that this would be cleanest to fix in leveldown. It does make sense for an Iterator to have start and end, if you think about it as a cursor that moves in sql-lite (so, websql - and on phonegap, etc) indexeddb https://developer.mozilla.org/en-US/docs/IndexedDB/IDBKeyRange The only other database I know that uses an api like that is couchdb which confuses people there two! http://grokbase.com/p/couchdb/user/096jayt85v/startkey-endkey-and-descending-true Having to reverse |
I'll have a look at those links but ultimately I might just have to trust you from an end-user perspective. |
+1 for exclusive Took me a while to figure out why I was getting extraneous keys :/ |
we need Level/leveldown#28 in to solve this properly, because it is necessary to check each key for whether it matches the comparator. |
What about |
@juliangruber +10. It's also my birthday today, so i can do that. ;asudhfalkhgfa;slfhl;aj;weir 🍰 |
yeah, perhaps, it certainly makes sense, but it might be kind of ugly? db.createReadStream({ start: 'foo', end: 'foo\xff' })
db.createReadStream({ start: 'foo', before: 'foo\xff' })
db.createReadStream({ after: 'foo', end: 'foo\xff' })
db.createReadStream({ after: 'foo', before: 'foo\xff' }) Is that intuitive enough? More 🍻 and 🍰 for you @hij1nx, hip hip 🎂 |
if we adopt min & max to "fix" the start & end issue (that they appear the wrong way around for most people for reversed streams), then this: db.createReadStream({ min: 'foo', max: 'foo\xff' })
db.createReadStream({ min: 'foo', before: 'foo\xff' })
db.createReadStream({ after: 'foo', max: 'foo\xff' })
db.createReadStream({ after: 'foo', before: 'foo\xff' }) perhaps a bit more messy because min/max is a bit more formal, in linguistic terms, than before/after, there's an odd disparity there, or is that just me? |
Yeah I feel the same way. It's just that it's super clear what before and after mean. I am for start/end, min/max, before/after, etc. always being both inclusive or exclusive, as they are word pairs and belong together. Otherwise that could be really confusing! |
It's slightly confusing but I think it makes the most sense. |
Just some ideas: // inc / exc
db.createReadStream({ inc: 'foo', inc: 'bar' });
db.createReadStream({ exc: 'foo', exc: 'bar' });
// sugar -> probably a module
db.createReadStream('[foo, bar)', {});
db.createReadStream({ start: '[foo', end: 'bar)' }); // collisions?
// verbose
db.createReadStream({ startingAt: 'foo', endingBefore: 'bar' });
db.createReadStream({ startingAfter: 'foo', endingAt: 'bar' });
// ..or
db.createReadStream({ startAt: 'foo', endBefore: 'bar' });
db.createReadStream({ startAfter: 'foo', endAt: 'bar' });
// ..or
db.createReadStream({ start: 'foo', endBefore: 'bar' });
db.createReadStream({ startAfter: 'foo', end: 'bar' }); |
what about:
I think the meaning here is completely clear... and it could be aliased to something that is easier to type:
or |
Not as pretty as the others but I think |
@dominictarr 👍. It's also easy to support ALL of them. |
I'm concerned about API surface area because it makes it more difficult to extend levelup, so lets not go overboard with aliasing. |
@rvagg agree. naturally, we'd convert any aliases into an internal representation immediately. I also have a funny feeling that @rvagg what do you think about: |
yep, lt, gt, lte, gte is a nice compromise actually, I keep on thinking minInclusive, maxInclusive, minExclusive, maxExclusive but it reminds me of too much Java code I've written. I think this thread is waiting for someone to submit a PR so we can just get on with it. |
right, so what we need for that is to expose the comparator on leveldown. Okay, I might tackle that this evening. |
okay, that didn't happen, but, soon. |
rather than using the comparator it'd probably be best to support inclusive and exclusive start & end in leveldown; it's an open question as to whether we do the reverse options switch in there too or if that's just a levelup thing. |
well, what are the reasons that leveldown shouldn't just have |
No good reason that I can think of except that somebody needs to do it, I'll put this on my todo list for when I find a spare moment, anyone else is welcome to have a crack at it though. Might be a good one for someone who's been a bit hesitant to get their hands dirty with V8/C++, start the job, submit a PR for feedback & suggestions and go from there. |
This is next item on my levelup to do list - my plan is to add this to leveldown in C++. |
okay so now that we actually have support for lt,gt,lte,gte and it works... and it took a long time to get it in, I now realize that having two possible lower bound / upper bound keys complicates code that deals with ranges. you have to always check if there is a lower bound, or the other lower bound. it would have been simpler to have a ( Another thing that makes ranges awkward is that bytewise encodes undefined, but json doesn't. I guess this is partially javascript's fault for having two nul values and that neither of them work right. |
make that travel back in time and fix bytewise AND indexeddb. |
Continued from #110 where the topic is slightly different.
Currently both
'start'
and'end'
are both inclusive. Options are to:'end'
exclusive'startExclusive'
&'endExclusive'
?Keeping in mind that we may be ditching
'start'
and'end'
in favour of'min'
and'max'
as per #110.The text was updated successfully, but these errors were encountered: