You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
"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) {
|
|
|
|
}
|
|
};
|
|
};
|