4.0.3 • Published 5 years ago

level-random v4.0.3

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

Build Status Coverage Status

level-random - read random levelup values

The level-random Node.js module implements a Transform stream for reading values of random keys in levelup.

Usage

Reading values for random keys from levelup.

const encode = require('encoding-down')
const leveldown = require('leveldown')
const levelup = require('levelup')
const lr = require('./')
const { pipeline, Readable, Writable } = require('readable-stream')

const db = levelup(encode(leveldown('/tmp/level-random-example.db')))

db.batch([
  { type: 'put', key: 'a', value: 'you' },
  { type: 'put', key: 'c', value: 'are' }
], er => {
  if (er) throw er

  const keys = ['a', 'b', 'c']

  pipeline(
    new Readable({
      read (length) {
        this.push(keys.shift() || null)
      }
    }),
    lr({ db: db }),
    new Writable({
      write (chunk, enc, cb) {
        console.log('%s', chunk)
        cb()
      }
    }),
    er => {
      if (er) throw er
      console.log('ok')
    }
  )
})

Run it:

$ node example.js

Types

opts()

Object passed to Transform stream constructor.

  • db The mandatory levelup instance.
  • errorIfNotFound Emit error if key is not found Boolean=false.
  • fillCache Fill LevelDB's LRU-cache Boolean=false.

Exports

level-random exports a sole function that returns a Transform stream which transforms keys to values.

var lr = require('level-random')
lr(opts())

At large, of course, we leverage the lexicographical sort order of keys in log structured databases to very efficiently stream ranges. Occasionally though, we have to read randomly from the store. This module provides a value stream for arbitrary keys, ignoring non-existing keys by default.

Installation

With npm, do:

$ npm install level-random

License

MIT License

4.0.3

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.0.2

5 years ago

2.0.3

5 years ago

3.0.1

5 years ago

3.0.0

6 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.3.1

9 years ago

1.3.0

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago