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

Commit a837e54

Browse files
committed
Add db.getMany(keys)
Ref Level/community#101
1 parent 795b393 commit a837e54

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ If no callback is passed, a promise is returned.
208208

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

211-
<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`.
211+
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`.
212212

213213
```js
214214
db.get('foo', function (err, value) {
@@ -225,10 +225,20 @@ db.get('foo', function (err, value) {
225225
})
226226
```
227227

228-
`options` is passed on to the underlying store.
228+
The optional `options` object is passed on to the underlying store.
229229

230230
If no callback is passed, a promise is returned.
231231

232+
<a name="get_many"></a>
233+
234+
### `db.getMany(keys[, options][, callback])`
235+
236+
Get multiple values from the store by an array of `keys`. The optional `options` object is passed on to the underlying store.
237+
238+
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`.
239+
240+
If no callback is provided, a promise is returned.
241+
232242
<a name="del"></a>
233243

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

lib/levelup.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ LevelUP.prototype.get = function (key, options, callback) {
185185
return callback.promise
186186
}
187187

188+
LevelUP.prototype.getMany = function (keys, options, callback) {
189+
return this.db.getMany(keys, options, callback)
190+
}
191+
188192
LevelUP.prototype.put = function (key, value, options, callback) {
189193
callback = getCallback(options, callback)
190194
callback = catering.fromCallback(callback)

test/self.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ suite({
3434
// TODO to make this pass:
3535
// - Have abstract-leveldown use level-errors
3636
// - Perform type checks in same order (e.g. check key before callback)
37-
// - Add db.isClosed(), isOpen() to abstract-leveldown
3837
suite({
3938
test: noop,
4039
factory: function (options) {

0 commit comments

Comments
 (0)