mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
804 B
38 lines
804 B
/*
|
|
* Db utilities.
|
|
*/
|
|
|
|
var Promise = require('bluebird');
|
|
|
|
// Delete all documents.
|
|
function deleteAll(db) {
|
|
return new Promise(function (resolve, reject) {
|
|
db.remove({
|
|
}, {
|
|
multi: true
|
|
}, function (err, numRemoved) {
|
|
console.log('removed', numRemoved, 'documents');
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve(numRemoved);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
// Find document(s).
|
|
function find(db, arg) {
|
|
return new Promise(function (resolve, reject) {
|
|
db.find(arg, function (err, docs) {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve(docs);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
exports.deleteAll = deleteAll;
|
|
exports.find = find;
|
|
|