A js-style LevelDB binding for node.


A js-style LevelDB binding for node.

The datatype is plain strings, support for buffers and other formats may be added.

var db = require('leveled')('/tmp/mydb');
db.putSync('foo', 'bar')
db.get('some', function (errval) {
  val == 'value';
db.find('*', function (errres) {
  console.log(res); // { 'a' : 'foo', 'aa' : 'baz', ... }   
  .put('foo', 'bar')
  .write(function (err) {
    // success 
$ npm install leveled

Instantiates a new DB at path, creating path if necessary.

Store val at key.

Get the value stored at key.

Delete the value stored at key.

Find all entries whose keys are in the give range.

  • from can be from / [from or (from
  • to can be to / to] or to)
db.range('[1337', '2337)', function (errres) {
  console.log(res) // { 1337 : 'foo', ..., 2336 : 'foo' }   

Find values.

db.find('ab*', function (errres) {
  console.log(res) // { 'aba' : 'foo', 'abzzz' : 'bar' } 

At the moment glob-style matching is not fully implemented, what works is

  • abc*
  • *

In the future it will work like redis's KEYS command:

  • ab? matches abc, not abcc
  • ab[1-3] matches ab1, ab2, ab3
  • ab[1-3]* etc.

Creates a new batch that queues up operations until its write method is invoked.

Apply the batch's operations to the DB.

On my mb pro:

$ node bench/bench.js
  benchmarking with 120,000 records, 24 chars each
          put :   128,479 w/s in    934ms
      putSync :   372,670 w/s in    322ms
        batch :   612,244 w/s in    196ms
    batchSync :   641,711 w/s in    187ms
          get :    58,881 r/s in  2,038ms
      getSync :   560,747 r/s in    214ms
     iterator :   220,588 r/s in    544ms

put oparations don't force a sync to disk, hence the get looking so slow. Iterators are faster for common tasks where you need to get many values anyways.

  • evaluate leveldb::Slice for storage
  • evaluate buffers as data type
  • evaluate storing native js objects
  • evaluate msgpack