Thanks to visit codestin.com
Credit goes to github.com

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

Commit 02cf2d3

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

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

.github/codecov.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
threshold: 5%
6+
patch: off

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- [`db.close([callback])`](#dbclosecallback)
2626
- [`db.put(key, value[, options][, callback])`](#dbputkey-value-options-callback)
2727
- [`db.get(key[, options][, callback])`](#dbgetkey-options-callback)
28+
- [`db.getMany(keys[, options][, callback])`](#dbgetmanykeys-options-callback)
2829
- [`db.del(key[, options][, callback])`](#dbdelkey-options-callback)
2930
- [`db.batch(array[, options][, callback])` _(array form)_](#dbbatcharray-options-callback-array-form)
3031
- [`db.batch()` _(chained form)_](#dbbatch-chained-form)
@@ -208,7 +209,7 @@ If no callback is passed, a promise is returned.
208209

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

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`.
212+
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`.
212213

213214
```js
214215
db.get('foo', function (err, value) {
@@ -225,10 +226,20 @@ db.get('foo', function (err, value) {
225226
})
226227
```
227228

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

230231
If no callback is passed, a promise is returned.
231232

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

234245
### `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)