organized level helpers ala mongo driver

v1.18.x
psychobunny 11 years ago
parent 46b6a93e98
commit a7582e2cca

@ -69,4 +69,22 @@
}
};
var helpers = {};
helpers.iterator = function(fn, keys, value, callback) {
var results = [];
async.each(keys, function(key, next) {
module[fn](key, value, function(err, result) {
results.push(result);
next();
});
}, function(err) {
callback(err, results);
});
};
module.helpers = module.helpers || {};
module.helpers.level = helpers;
}(exports));

@ -3,6 +3,8 @@
var async = require('async');
module.exports = function(db, module) {
var helpers = module.helpers.level;
module.setObject = function(key, obj, callback) {
async.parallel([
function(next) {
@ -82,7 +84,7 @@ module.exports = function(db, module) {
};
module.getObjectsFields = function(keys, fields, callback) {
module.iterator('getObjectFields', keys, fields, callback);
helpers.iterator('getObjectFields', keys, fields, callback);
};
module.getObjectKeys = function(key, callback) {

@ -1,6 +1,8 @@
"use strict";
module.exports = function(db, module) {
var helpers = module.helpers.level;
module.listPrepend = function(key, value, callback) {
module.getListRange(key, 0, -1, function(err, list) {
var arr = list || [];

@ -4,6 +4,8 @@ var nconf = require('nconf'),
async = require('async');
module.exports = function(db, module) {
var helpers = module.helpers.level;
module.close = function(callback) {
db.close(callback);
};
@ -78,18 +80,5 @@ module.exports = function(db, module) {
// <__<
};
module.iterator = function(fn, keys, value, callback) {
var results = [];
async.each(keys, function(key, next) {
module[fn](key, value, function(err, result) {
results.push(result);
next();
});
}, function(err) {
callback(err, results);
});
};
return module;
};

@ -3,6 +3,8 @@
var async = require('async');
module.exports = function(db, module) {
var helpers = module.helpers.level;
module.setAdd = function(key, value, callback) {
module.getListRange(key, 0, -1, function(err, set) {
if (set.indexOf(value) === -1) {
@ -40,7 +42,7 @@ module.exports = function(db, module) {
};
module.isMemberOfSets = function(sets, value, callback) {
module.iterator('isSetMember', sets, value, callback);
helpers.iterator('isSetMember', sets, value, callback);
};
module.getSetMembers = function(key, callback) {

@ -4,6 +4,8 @@ var async = require('async');
module.exports = function(db, module) {
var helpers = module.helpers.level;
module.sortedSetAdd = function(key, score, value, callback) {
module.getListRange(key, 0, -1, function(err, set) {
set = set.filter(function(a) {return a.value !== value.toString();});

Loading…
Cancel
Save