Level / abstract-level

Abstract class for a lexicographically sorted key-value database.
MIT License
123 stars 8 forks source link

Add builtin sublevels :sparkles: #8

Closed vweevers closed 2 years ago

vweevers commented 2 years ago

I initially wanted to wait with this and instead fork subleveldown and keep that functionality in a separate module, but I figured that would require breaking changes later on. In addition, I've yet to benchmark abstract-level versus levelup and abstract-leveldown; including sublevels now saves me from having to benchmark twice.

Adds a db.sublevel(name[, options]) method that works the same as subleveldown except it returns an abstract-level database instead of a levelup database. Data-wise there's no change, so an abstract-level sublevel can read sublevels previously created with (and populated by) subleveldown.

Uses code and tests from subleveldown. Where possible, I converted functional tests (against a memdown db) to unit tests (against a mocked database). The abstract test suite also repeats itself, to run both on a regular database, and a sublevel of the database.

Comes with some new features compared to subleveldown:

vweevers commented 2 years ago

Review of the following is welcome: function signatures of the public API, docs (README.md and UPGRADING.md), TypeScript types, and LICENSE (see above comment). The code itself is covered by tests (now including the new sublevel option for batches) but a high-level review on that would be welcome too (in terms of code complexity, plugin compatibility, extensibility, etc).

vweevers commented 2 years ago

Merging because I have some cleanup to do on the main branch (has some fixup commits I forgot to squash). Retroactive review is of course still welcome.