Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
Add db.getMany(keys)
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Sep 25, 2021
1 parent 795b393 commit a837e54
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,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 +225,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 a837e54

Please sign in to comment.