node-le

Generator style node interface to LevelDB

Downloads
28
Stars
10
Committers
2

Le db

Generator style node interface to LevelDB.

Usage

Works best with co.

var le = require('le');
var co = require('co');

var db = le('db');

co(function*(){
  yield db.set('foo', 'bar');
  console.log('foo: %s', yield db.get('foo'));
})();

Installation

$ npm install le

Stability

Expect things to change as le grows with its usage. So it's only being used in tiny webapps.

Roadmap

  • get, set, delete
  • batches
  • prefix ranges
  • interval ranges
  • test suite
  • streaming iteration
  • encodings
  • plugin interface (no monkey patching!)
  • nesting
  • client

API

db(path)

Create or open the db at path.

db#get*(key)

Get the value at key.

db#set*(key, value)

Set the value at key to value.

db#del*(key)

Delete the value at key.

db#batch()

Create a batch.

batch#set(key, value)

Queue setting key to value.

batch#del(key)

Queue deleting the value at key.

batch#end*()

Write the batch of operations.

db#keys*([range])

Get all keys (inside range).

db#values*([range])

Get all values (whose keys are inside range).

Ranges

db#keys() and db#values() accept string ranges of those formats:

  • ""/"*": get all

  • "prefix*": all keys must start with prefix

  • "[from,to]", "[from,to)", "(from,to]", "(from,to)": all keys must be inside the interval, see interval notations. For infinity to x and vice versa omit the boundary, like [,to].

    In most cases that's less verbose than:

{
  "gte": "from",
  "lte": "to"
}

or

{
  "gte": "prefix!",
  "lte": "prefix!~"
}

which can be expressed simply as [from,to] and prefix!*.

Encoding

For now, everything is stored as JSON.

Debugging

Set the env var DEBUG=le to see what and when it's doing internal operations.

Y u do this

  • want db.use() instead of monkey patching
  • generators for async ops
  • generators for streams
  • efficient nesting and less verbose ranges

Associated libraries

License

MIT