Skip to content

Commit

Permalink
Add db.getMany(keys)
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Sep 30, 2021
1 parent 9040a37 commit df5f239
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

`deferred-leveldown` implements the basic [abstract-leveldown](https://github.com/Level/abstract-leveldown) API so it can be used as a drop-in replacement where `leveldown` is needed.

`put()`, `get()`, `del()`, `batch()` and `clear()` operations are all queued and kept in memory until the `abstract-leveldown`-compatible object has been opened through `deferred-leveldown`'s `open()` method.
`put()`, `get()`, `getMany()`, `del()`, `batch()` and `clear()` operations are all queued and kept in memory until the `abstract-leveldown`-compatible object has been opened through `deferred-leveldown`'s `open()` method.

`batch()` operations will all be replayed as the array form. Chained-batch operations are converted before being stored.

Expand Down
4 changes: 2 additions & 2 deletions deferred-leveldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
const AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN
const inherits = require('inherits')
const DeferredIterator = require('./deferred-iterator')
const deferrables = 'put get del batch clear'.split(' ')
const optionalDeferrables = 'approximateSize compactRange'.split(' ')
const deferrables = ['put', 'get', 'getMany', 'del', 'batch', 'clear']
const optionalDeferrables = ['approximateSize', 'compactRange']

function DeferredLevelDOWN (db) {
AbstractLevelDOWN.call(this, db.supports || {})
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
"UPGRADING.md"
],
"dependencies": {
"abstract-leveldown": "^7.0.0",
"abstract-leveldown": "^7.2.0",
"inherits": "^2.0.3"
},
"devDependencies": {
"airtap": "^4.0.3",
"airtap-playwright": "^1.0.1",
"dependency-check": "^3.3.0",
"hallmark": "^3.1.0",
"memdown": "^6.0.0",
"memdown": "^6.1.0",
"nyc": "^15.1.0",
"reachdown": "^1.0.0",
"standard": "^16.0.3",
Expand Down
19 changes: 16 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ const testCommon = suite.common({
createIfMissing: false,
errorIfExists: false,

// Opt-in to new clear() tests
clear: true
// Opt-in to new tests
clear: true,
getMany: true
})

// Hack: disable failing tests. These fail on serialize tests
require('abstract-leveldown/test/put-test').args = noop
require('abstract-leveldown/test/get-test').args = noop
require('abstract-leveldown/test/get-many-test').args = noop
require('abstract-leveldown/test/del-test').args = noop

// This fails on "iterator has db reference" test, as expected because
Expand Down Expand Up @@ -235,7 +237,7 @@ test('keys and values should not be serialized', function (t) {

function noop () {}

t.plan(8)
t.plan(9)

t.test('put', function (t) {
const calls = []
Expand All @@ -261,6 +263,17 @@ test('keys and values should not be serialized', function (t) {
})
})

t.test('getMany', function (t) {
const calls = []
const ld = Db('getMany', function (keys, cb) { calls.push(keys[0]) })
ITEMS.forEach(function (key) { ld.getMany([key], noop) })
ld.open(function (err) {
t.error(err, 'no error')
t.same(calls, ITEMS, 'value ok')
t.end()
})
})

t.test('del', function (t) {
const calls = []
const ld = Db('del', function (key, cb) { calls.push(key) })
Expand Down

0 comments on commit df5f239

Please sign in to comment.