Skip to content

Commit 7ee8b6c

Browse files
author
Tim Kuijsten
committed
differentiate undefined from not found
abstract-level requires differentiation between undefined as a value and not exists. The IndexedDB API has a note explaining openCursor can be used for this instead of get. refs Level#41
1 parent 0348bde commit 7ee8b6c

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ Level.prototype._open = function(options, callback) {
4040
}
4141

4242
Level.prototype._get = function (key, options, callback) {
43-
this.idb.get(key, function (value) {
44-
if (value === undefined) {
43+
// should differentiatie between undefined values and "not found"
44+
var found, value;
45+
function onEnd() {
46+
if (!found) {
4547
// 'NotFound' error, consistent with LevelDOWN API
4648
return callback(new Error('NotFound'))
4749
}
@@ -55,7 +57,16 @@ Level.prototype._get = function (key, options, callback) {
5557
else value = new Buffer(String(value))
5658
}
5759
return callback(null, value, key)
58-
}, callback)
60+
};
61+
var opts = {
62+
keyRange: key,
63+
onEnd: onEnd,
64+
onError: callback
65+
};
66+
this.idb.iterate(function(item) {
67+
found = true;
68+
value = item;
69+
}, opts);
5970
}
6071

6172
Level.prototype._del = function(id, options, callback) {

0 commit comments

Comments
 (0)