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 Oct 1, 2021
1 parent 795b393 commit 02cf2d3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
coverage:
status:
project:
default:
threshold: 5%
patch: off
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- [`db.close([callback])`](#dbclosecallback)
- [`db.put(key, value[, options][, callback])`](#dbputkey-value-options-callback)
- [`db.get(key[, options][, callback])`](#dbgetkey-options-callback)
- [`db.getMany(keys[, options][, callback])`](#dbgetmanykeys-options-callback)
- [`db.del(key[, options][, callback])`](#dbdelkey-options-callback)
- [`db.batch(array[, options][, callback])` _(array form)_](#dbbatcharray-options-callback-array-form)
- [`db.batch()` _(chained form)_](#dbbatch-chained-form)
Expand Down Expand Up @@ -208,7 +209,7 @@ If no callback is passed, a promise is returned.

### `db.get(key[, options][, callback])`

<code>get()</code> is the primary method for fetching data from the store. The `key` can be of any type. If it doesn't exist in the store then the callback or promise will receive an error. A not-found err object will be of type `'NotFoundError'` so you can `err.type == 'NotFoundError'` or you can perform a truthy test on the property `err.notFound`.
Get a value from the store by `key`. The `key` can be of any type. If it doesn't exist in the store then the callback or promise will receive an error. A not-found err object will be of type `'NotFoundError'` so you can `err.type == 'NotFoundError'` or you can perform a truthy test on the property `err.notFound`.

```js
db.get('foo', function (err, value) {
Expand All @@ -225,10 +226,20 @@ db.get('foo', function (err, value) {
})
```

`options` is passed on to the underlying store.
The optional `options` object is passed on to the underlying store.

If no callback is passed, a promise is returned.

<a name="get_many"></a>

### `db.getMany(keys[, options][, callback])`

Get multiple values from the store by an array of `keys`. The optional `options` object is passed on to the underlying store.

The `callback` function will be called with an `Error` if the operation failed for any reason. If successful the first argument will be `null` and the second argument will be an array of values with the same order as `keys`. If a key was not found, the relevant value will be `undefined`.

If no callback is provided, a promise is returned.

<a name="del"></a>

### `db.del(key[, options][, callback])`
Expand Down
4 changes: 4 additions & 0 deletions lib/levelup.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ LevelUP.prototype.get = function (key, options, callback) {
return callback.promise
}

LevelUP.prototype.getMany = function (keys, options, callback) {
return this.db.getMany(keys, options, callback)
}

LevelUP.prototype.put = function (key, value, options, callback) {
callback = getCallback(options, callback)
callback = catering.fromCallback(callback)
Expand Down
1 change: 0 additions & 1 deletion test/self.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ suite({
// TODO to make this pass:
// - Have abstract-leveldown use level-errors
// - Perform type checks in same order (e.g. check key before callback)
// - Add db.isClosed(), isOpen() to abstract-leveldown
suite({
test: noop,
factory: function (options) {
Expand Down

0 comments on commit 02cf2d3

Please sign in to comment.