Skip to content

Commit

Permalink
Merge 6769edd into cd99bf5
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson committed Dec 13, 2015
2 parents cd99bf5 + 6769edd commit 45a89ae
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
7 changes: 3 additions & 4 deletions localstorage-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ LocalStorageCore.prototype.remove = function (key, callback) {
LocalStorageCore.destroy = function (dbname, callback) {
var prefix = createPrefix(dbname);
callbackify(callback, function () {
var len = storage.length;
var i = -1;
while (++i < len) {
var i = storage.length;
while (--i >= 0) {
var key = storage.key(i);
if (key && key.substring(0, prefix.length) === prefix) {
if (key.substring(0, prefix.length) === prefix) {
storage.removeItem(key);
}
}
Expand Down
33 changes: 33 additions & 0 deletions tests/custom-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,39 @@ module.exports.all = function (leveldown, tape, testCommon) {
});
});

tape('test .destroy with multiple dbs', function (t) {
var db = levelup('a', {db: leveldown});
var db2 = levelup('b', {db: leveldown});
var db3 = levelup('c', {db: leveldown});
db.put('1', '1', function (err) {
t.notOk(err, 'no error');
db2.put('1', '1', function (err) {
t.notOk(err, 'no error');
db3.put('1', '1', function (err) {
t.notOk(err, 'no error');
db2.put('2', '2', function (err) {
t.notOk(err, 'no error');
db2.put('3', '3', function (err) {
t.notOk(err, 'no error');
leveldown.destroy('b', function (err) {
t.notOk(err, 'no error');
db3.get('1', function (err, res) {
t.notOk(err, 'no error');
t.equal(res, '1');
db2 = levelup('b', {db: leveldown});
db2.get('3', function (err) {
t.ok(err);
t.end();
});
});
});
});
});
});
});
});
});

tape('test escaped db name', function (t) {
var db = levelup('bang!', {db: leveldown});
var db2 = levelup('bang!!', {db: leveldown});
Expand Down

0 comments on commit 45a89ae

Please sign in to comment.