level-range

0.0.0 • Public • Published

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)

Readme

Keywords

none

Package Sidebar

Install

npm i level-range

Weekly Downloads

0

Version

0.0.0

License

MIT

Last publish

Collaborators

  • juliangruber