union-hyperdb is a wrapper around multiple hyperdbs that supports nesting and/or layering of hyperdbs within a parent database:
- Lightweight forking and layering operations are supported through a
parents
relationship. If an entry can't be found in the main tree, the search will traverse into all parents. This creates a union filesystem-like view over the underlying databases. - Cross-db symlinking (of both live and versioned dbs) is supported through special
Link
entries.
No external indexing is required, and sub-dbs are instantiated dynamically when first needed.
npm i union-hyperdb
var hypercore = require('hypercore')
var uniondb = require('union-hyperdb')
var ram = require('random-access-memory')
// A hypercore factory function is required, because union-hyperdb constructs hyperdbs dynamically.
var factory = function (key, version, cb) {
return hypercore(ram, key, { version })
}
var baseTree = factory()
var db = uniondb(baseTree, factory)
union-hyperdb implements the hyperdb API, with the addition of the methods described below.
Since union-hyperdbs need to dynamically create sub-hyperdbs, it needs to be provided with a hypercore factory function.
factory
is a function that takes a key and an optional version, and returns a hypercore:
opts
are hyperdb options, but with the important addition of:
{
parents: [] // A list of { key: key, version: version} objects specifying parent append-trees.
}
Create a link record that references another hyperdb (specified by target
)
name
is the symlink's absolute path
target
can be either:
- An object of the form
{ key: <key>, path: <path> }
- A string of the form
dat://<key>/<path>
or<key>/<path>
(assuming the latter form is a dat key + a path).opts
is an optional object of the form:
{
version: <unspecified, as in latest> // The desired db version, if the link should be versioned (static).
}
Create a lexicographic iterator over the database.
opts
are LevelDB-style options (gt
, gte
, lt
, lte
, and reverse
).
Compute a layer index over the entire database, such that lookups will require constant time (in the number of layers).
Note: If one does not call index
before calling read-intensive methods, then those methods might need to sequentially search each layer for content.