Socket
Book a DemoInstallSign in
Socket

level-range

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

level-range

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

latest
Source
npmnpm
Version
0.0.0
Version published
Maintainers
1
Created
Source

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)

Keywords

leveldb

FAQs

Package last updated on 19 Mar 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts