co-nedb-ex
v1.0.0
Published
nedb generator goodness for co, preserving the original object
Downloads
5
Readme
co-nedb
Nedb made more awesome with generators.
This fork preserves the original supplied NeDB object, but links to the same instance.
- You can use the callbacks on the original object.
Installation
$ npm install co-nedb
Setup
Call wrap()
on collections to make them generator friendly:
var Datastore = require('nedb');
var wrap = require('co-nedb');
var db = new Datastore({ autoload: true }); // in-memory database
var users = wrap(db); // !!! RETURNS A NEW DB OBJECT (the original is NOT MODIFED) !!!
Example
Simple example:
yield users.remove({});
yield users.insert({ name: 'Tobi', species: 'ferret' });
yield users.insert({ name: 'Loki', species: 'ferret' });
yield users.insert({ name: 'Jane', species: 'ferret' });
var res = yield users.findOne({ name: 'Tobi' });
res.name.should.equal('Tobi');
var res = yield users.find({ species: 'ferret' });
res.should.have.length(3);
Parallel inserts:
yield users.remove({});
yield [
users.insert({ name: 'Tobi', species: 'ferret' }),
users.insert({ name: 'Loki', species: 'ferret' }),
users.insert({ name: 'Jane', species: 'ferret' })
];
var res = yield users.findOne({ name: 'Tobi' });
res.name.should.equal('Tobi');
var res = yield users.find({ species: 'ferret' });
res.should.have.length(3);
License
MIT
Changelog
v2.0.0 (18 Oct 2014)
- Bumped thunkify version from
0.0.1
to2.1.2
. - Removed nedb as a dependency
- Added .npmignore