Skip to content

Get the first result in a range, using an iterator or stream

License

Notifications You must be signed in to change notification settings

vweevers/level-probe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

level-probe

Get the first result in a range, using an iterator or stream.

npm status Travis build status AppVeyor build status Dependency status

example

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 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 do:

npm install level-probe

license

MIT © Vincent Weevers

About

Get the first result in a range, using an iterator or stream

Resources

License

Stars

Watchers

Forks

Packages

No packages published