Skip to content

Commit

Permalink
Merge 699e5ba into c7d27ee
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson authored Dec 11, 2016
2 parents c7d27ee + 699e5ba commit b447889
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function LDIterator(db, options) {
this._lt = options.lt;
this._lte = options.lte;
this._exclusiveStart = options.exclusiveStart;
this._keysOnly = options.values === false;
this._limit = options.limit;
this._count = 0;

Expand Down Expand Up @@ -64,6 +65,10 @@ LDIterator.prototype._next = function (callback) {
}

self._pos += self._reverse ? -1 : 1;
if (self._keysOnly) {
return callback(null, key);
}

self.db.container.getItem(key, function (err, value) {
if (err) {
if (err.message === 'NotFound') {
Expand Down
53 changes: 50 additions & 3 deletions tests/custom-tests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

var levelup = require('levelup');

var LocalStorage = require('../lib/localstorage').LocalStorage;

module.exports.setUp = function (leveldown, test, testCommon) {
test('setUp common', testCommon.setUp);
test('setUp db', function (t) {
Expand Down Expand Up @@ -227,12 +228,17 @@ module.exports.all = function (leveldown, tape, testCommon) {
var noerr = function (err) {
t.error(err, 'opens crrectly');
};
var noop = function () {};
var noop = function () {
};
var iterator;
db.open(noerr);
db.put('1', '1', noop);
db.put('2', '2', noop);
iterator = db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '1' });
iterator = db.iterator({
keyAsBuffer: false,
valueAsBuffer: false,
start: '1'
});

var zalgoReleased = false;
iterator.next(function (err, key, value) {
Expand All @@ -254,4 +260,45 @@ module.exports.all = function (leveldown, tape, testCommon) {
});
t.ok(!zalgoReleased, 'zalgo not released (1)');
});

tape('bypasses getItem for keys-only db streams', function (t) {
var origGetItem = LocalStorage.prototype.getItem;
LocalStorage.prototype.getItem = function () {
throw new Error('shouldn\'t get called for keys-only db streams');
};

var db = levelup('ooga', { db: leveldown });
var batch = [
{
key: 'a',
value: '1',
type: 'put'
},
{
key: 'b',
value: '2',
type: 'put'
},
{
key: 'c',
value: '3',
type: 'put'
},
];

db.batch(batch, function () {
db.createKeyStream({
start: 'c'
})
.on('data', function (key) {
t.equals(key, 'c');
db.close(function (err) {
t.notOk(err, 'no error');
// unhack getItem
LocalStorage.prototype.getItem = origGetItem;
t.end();
});
});
});
});
};

0 comments on commit b447889

Please sign in to comment.