monkify
v1.0.2
Published
A fork of tj's co-monk. co/thunkify wrappers updated for recent versions of monk.
Downloads
5
Maintainers
Readme
monkify
A fork of tj's co-monk. co/thunkify wrappers updated for recent versions of monk.
Installation
$ npm install monkify
Setup
Call wrap()
on collections to make them generator friendly:
var monk = require('monk');
var wrap = require('monkify');
var db = monk('localhost/test');
var users = wrap(db.get('users'));
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');
yield users.removeById(res._id);
var res = yield users.find({ species: 'ferret' });
res.should.have.length(2);
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');
yield users.removeById(res._id);
var res = yield users.find({ species: 'ferret' });
res.should.have.length(2);
License
MIT