-
-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add clear() #669
Merged
Add clear() #669
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c808bd9
Add clear() method to delete all entries or a range
vweevers 06fe4c2
Upgrade deferred-leveldown from ~5.1.0 to ~5.2.0
vweevers 62492c2
Upgrade encoding-down devDependency from ^6.0.0 to ^6.2.0
vweevers 47139d4
Add link to Level/community#79
vweevers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
var test = require('tape') | ||
var memdown = require('memdown') | ||
var encode = require('encoding-down') | ||
var concat = require('level-concat-iterator') | ||
var levelup = require('../lib/levelup') | ||
|
||
test('clear()', function (t) { | ||
function makeTest (name, fn) { | ||
t.test(name, function (t) { | ||
var mem = memdown() | ||
|
||
mem.open(function (err) { | ||
t.ifError(err, 'no open error') | ||
|
||
mem.batch([ | ||
{ type: 'put', key: '"a"', value: 'a' }, | ||
{ type: 'put', key: '"b"', value: 'b' } | ||
], function (err) { | ||
t.ifError(err, 'no batch error') | ||
|
||
mem.close(function (err) { | ||
t.ifError(err, 'no close error') | ||
fn(t, mem) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
function verify (t, db, expectedKey) { | ||
concat(db.iterator({ keyAsBuffer: false }), function (err, entries) { | ||
t.ifError(err, 'no concat error') | ||
t.same(entries.map(function (e) { return e.key }), [expectedKey], 'got expected keys') | ||
db.close(t.end.bind(t)) | ||
}) | ||
} | ||
|
||
makeTest('clear() without encoding, without deferred-open', function (t, mem) { | ||
var db = levelup(mem) | ||
|
||
db.open(function (err) { | ||
t.ifError(err) | ||
|
||
db.clear({ gte: '"b"' }, function (err) { | ||
t.ifError(err, 'no clear error') | ||
verify(t, db, '"a"') | ||
}) | ||
}) | ||
}) | ||
|
||
makeTest('clear() without encoding, with deferred-open', function (t, mem) { | ||
var db = levelup(mem) | ||
|
||
db.clear({ gte: '"b"' }, function (err) { | ||
t.ifError(err, 'no clear error') | ||
verify(t, db, '"a"') | ||
}) | ||
}) | ||
|
||
makeTest('clear() with encoding, with deferred-open', function (t, mem) { | ||
var db = levelup(encode(mem, { keyEncoding: 'json' })) | ||
|
||
db.clear({ gte: 'b' }, function (err) { | ||
t.ifError(err, 'no clear error') | ||
verify(t, db, 'a') | ||
}) | ||
}) | ||
|
||
makeTest('clear() with encoding, without deferred-open', function (t, mem) { | ||
var db = levelup(encode(mem, { keyEncoding: 'json' })) | ||
|
||
db.open(function (err) { | ||
t.ifError(err) | ||
|
||
db.clear({ gte: 'b' }, function (err) { | ||
t.ifError(err, 'no clear error') | ||
verify(t, db, 'a') | ||
}) | ||
}) | ||
}) | ||
|
||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not 100% sure about the argument (
options
). I figured a listener might want to inspect the range options, to find out what was deleted. But that information is not exact (in contrast with theput
,del
andbatch
events that tell you exactly which keys were modified).