Skip to content

Commit 274f982

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 18965a8 commit 274f982

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
@@ -38,8 +38,10 @@ Level.prototype._open = function(options, callback) {
3838
}
3939

4040
Level.prototype._get = function (key, options, callback) {
41-
this.idb.get(key, function (value) {
42-
if (value === undefined) {
41+
// should differentiatie between undefined values and "not found"
42+
var found, value;
43+
function onEnd() {
44+
if (!found) {
4345
// 'NotFound' error, consistent with LevelDOWN API
4446
return callback(new Error('NotFound'))
4547
}
@@ -53,7 +55,16 @@ Level.prototype._get = function (key, options, callback) {
5355
else value = new Buffer(String(value))
5456
}
5557
return callback(null, value, key)
56-
}, callback)
58+
};
59+
var opts = {
60+
keyRange: key,
61+
onEnd: onEnd,
62+
onError: callback
63+
};
64+
this.idb.iterate(function(item) {
65+
found = true;
66+
value = item;
67+
}, opts);
5768
}
5869

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

0 commit comments

Comments
 (0)