node-foundationdb icon indicating copy to clipboard operation
node-foundationdb copied to clipboard

Added support for including keyspace ends in the ranges

Open keijokapp opened this issue 1 year ago • 0 comments

I've implemented a concept solution for #78. I think this is the best option, ie least bloat for the maximum robustness. The implementation hasn't been tested and needs more documentation. I'm interested in any feedback.

The PR does the following:

  • Add StartsWith variants for all methods that deal with ranges. Those are what developers should use to get the prefix behavior. The original methods continue work as before by default.
  • Modify Subspace#packRange to deal with start/end combinations. Add Subspace#packRangeStartsWith for handling prefixes. Like before, the later is what developers should use for prefix behavior but the original one stays backwards compatible by default.
  • Make all packing/unpacking go through Subspace, so that there's only one central place for all that complexity. While packing/unpacking individual keys/values doesn't strictly need to go through subspace, there's now less reason to keep the transformer copies around. Maybe it should be a separate commit.
  • Add _noDefaultPrefix flag to subspace and Subspace#noDefaultPrefix and Database#noDefaultPrefix methods. These switch the subspace to a mode that enables including key space ends in the ranges. The naming of these could be improved.
  • Make end key default to subspace end in the noDefaultPrefix mode.
  • Make start key optional, defaulting to subspace start. This is good for consistency but also useful for abstractions that want to specify the range in an encoding agnostic way but still benefit from automatic key encoding/decoding and type safety.

keijokapp avatar May 10 '24 21:05 keijokapp