"use strict"; // function prefixSearch(...) { // ... // } module.exports = function createLMDBBackend(instance) { return { getKey: function (key) { // return value, or throw if non-existent return instance.get(key); }, putKey: function (key, value) { // TODO: compare-and-set in API? // NOTE: returns `false` if `ifVersion` check failed, but we are not currently using that feature return instance.put(key, value); }, getKeyRange: function* (lowestKey, lowestInclusive, highestKey, highestInclusive) { // NOTE: Range requests in lmdb are start-inclusive but end-exclusive yield* instance.getRange({ start: lowestKey, end: highestKey }) .filter(({ key }) => { if (!lowestInclusive && lowestKey.equals(key)) { return false; } else { return true; } }); if (highestInclusive && instance.doesExist(highestKey)) { yield { key: highestKey, value: instance.get(highestKey) }; } return; }, runInTransaction: function (callback) { } }; };