level-sublevel for co
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE
Makefile
Readme.md
index.js
package.json
test.js

Readme.md

Co Sublevel

Build Status

level-sublevel for co

Wraps a sublevel-wrapped levelup with co-level

usage

read the test.js for more examples.

var level = require('co-sublevel')
  , memdown = function (l) { return new (require('memdown'))(l) }
  , co = require('co')

var db = level('db', { db: memdown, type: 'json' })

co(function *() {
  var sub = db.sublevel('s');

  yield sub.put('x', 'y');

  var res = yield sub.get('x');

  assert(res === 'y');
})();

streams

You can yield a stream coming from levelup database using co-from-stream

var wrapStream = require('co-from-stream')

co(function *() {
  yield db.put('a', 'b');
  yield db.put('c', 'd');

  var read = wrapStream(db.readStream());

  var data = [], buf;
  while (buf = yield read()) {
    data.push({}[buf.key] = buf.value);
  }

  data.should.be.a.Array;
  data.length.should.be.exactly(2);
  data[0].should.be.exactly('b');
})();

License

MIT