https://github.com/vweevers/level-probe
Get the first result in a range, using an iterator or stream
https://github.com/vweevers/level-probe
Last synced: 12 months ago
JSON representation
Get the first result in a range, using an iterator or stream
- Host: GitHub
- URL: https://github.com/vweevers/level-probe
- Owner: vweevers
- License: mit
- Created: 2016-02-05T14:30:24.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-02-07T03:03:10.000Z (over 10 years ago)
- Last Synced: 2025-06-22T19:08:52.665Z (12 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# level-probe
**Get the first result in a range, using an [iterator](https://github.com/vweevers/level-iterator) or stream.**
[](https://www.npmjs.org/package/level-probe) [](http://travis-ci.org/vweevers/level-probe) [](https://ci.appveyor.com/project/vweevers/level-probe) [](https://david-dm.org/vweevers/level-probe)
## example
```js
const probe = require('level-probe')
const disk = require('test-level')({ clean: true })
const db = disk()
db.batch([
{ key: 'a', value: 'value a' },
{ key: 'b', value: 'value b' },
{ key: 'c', value: 'value c' }
], function(err) {
probe(db, { gte: 'b' }, function(err, kv){
console.log(kv)
})
probe.value(db, { lt: 'x', reverse: true }, function(err, val){
console.log(val)
})
probe(db, { gt: 'd', lt: 'x' }, function(err){
console.log(err.message)
console.log(err.notFound)
})
})
```
Output:
```
{ key: 'b', value: 'value b' }
value c
No result in range { gt: "d", lt: "x" }
true
```
## `probe(db, [opts], callback)`
- If `opts.iterate` is `false`, `level-probe` will use a stream. If `true`, it will use an iterator or throw if iterators are not available. If not specified, it will prefer iterators and fall back to streams.
- Other options are passed to [level-iterator](https://github.com/vweevers/level-iterator) or `db.createReadStream()`
## `probe.key(db, [opts], callback)`
Shortcut to `probe(db, { values: false }, callback)`.
## `probe.value(db, [opts], callback)`
Shortcut to `probe(db, { keys: false }, callback)`.
## install
With [npm](https://npmjs.org) do:
```
npm install level-probe
```
## license
[MIT](http://opensource.org/licenses/MIT) © Vincent Weevers