JSPM

level-range

0.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q16005F
  • License MIT

Find all K/V-pairs prefixed by a certain key.

Package Exports

  • level-range

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (level-range) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

level-range

Find all K/V-pairs prefixed by a certain key.

An often used range query when working with leveldb.

Usage

Given this data stored in a leveldb at /tmp/db:

{
  "bucket:a-bucket:0" : "some",
  "bucket:a-bucket:1" : "test",
  "bucket:a-bucket:2" : "data",
  "bucket:another-one:0" : "nope"
}

and a script test.js that takes argv and outputs found data:

var levelup = require('levelup');
var db = levelup('/tmp/db');
var JSONStream = require('JSONStream');
var range = require('level-range');

range(db, 'bucket:%s:', process.argv[2])
.pipe(JSONStream.stringify())
.pipe(process.stdout);

The output will be:

$ node test.js a-bucket
[
{"key":"0","value":"some"}
,
{"key":"1","value":"test"}
,
{"key":"2","value":"data"}
]

$ node test.js another-bucket
[
{"key":"0","value":"nope"}
]

API

range(db, prefix, args...)

Create a range stream. args will be fed into util.formt together with prefix so you can use placeholders there.

Installation

With npm do:

$ npm install level-range

License

(MIT)