exports['multiple set'] = function (assert) {
    Store(file, function (error, db) {
        if (error) throw error;

        range(0,100).forEach(function (x) {
            var key = 'key' + (x).toString();
            db.set(key, x, function (sErr) {
                assert.ok(!sErr);
                if (x == 99) {
                    range(0,100).forEach(function (y) {
                        var key = 'key' + (y).toString();
                        db.get(key, function (gErr, val) {
                            assert.ok(!gErr);
                            assert.equal(y, val);
                        });
                    });
                }
            });
        });
    });
};
Exemple #2
0
function Cart(options) {
    var self = this;
    
    options = options || {};
    options.maxAge = options.maxAge || 3600000; // Expunge after an hour
    var dbFile = options.dbFile || __dirname + "/sessions.db";
    ConnectStore.call(this, options);
    Store(dbFile, function (err, db) {
        if (err) throw err;
        self.db = db;
        db.filter(
            function (key, item) {
                item = JSON.parse(item);
                return item.lastAccess > Date.now() - options.maxAge;
            },
            function (key, item) {
                db.remove(key);
            }
        );
    });
};
Exemple #3
0
function pf (db, def, cb) {
    if (cb === undefined) { cb = def; def = {} }
    if (!def) def = {};
    
    if (typeof db === 'string') {
        Store({ filename : db, json : true }, function (err, db) {
            if (err) cb(err)
            else load(db, def, cb);
        });
    }
    else {
        var missing = [ 'get', 'set', 'remove', 'all' ]
            .filter(function (x) { return !db[x] })
        ;
        if (missing.length) {
            cb('The store is missing: ' + missing.join(', '));
        }
        else {
            load(db, def, cb);
        }
    }
}
Exemple #4
0
var Hash = require('traverse/hash');
var qs = require('querystring');
var Store = require('supermarket');

var User = require('./models/user');
var Session = require('./session');

var sessions = Store({
    filename : process.cwd() + '/data/sessions.db',
    json : true
});

module.exports = function (users, cb) {
    cb(function (client, conn) {
        var self = this;
        
        self.session = function (f) {
            var cookie = conn.stream.socketio.request.headers.cookie;
            var sid = qs.parse(cookie).connect.sid;
            if (!sid) f('Not authenticated');
            else fromSid(users, conn, sid, f);
        };
        
        self.authenticate = function (name, pass, f) {
            var user = users[name];
            if (!user || User.hash(pass) != user.hash) {
                f('Invalid');
            }
            else {
                fromUser(user, conn, f);
            }
Exemple #5
0
var github = new (require('github').GitHubApi)(true).getCommitApi();
var Hash = require('traverse/hash');
var Store = require('supermarket');
var DNode = require('dnode');

var dbfile = __dirname + '/gitwatch.db';
var db = Store({ filename : dbfile, json : true});

//Look again. Your constructor is now a dnode service!
DNode(Branches).listen(1234);



//This is a terrible name.
//Channels isn't a good name either.
function Branches () {
    //Watch a new repo for a given channel
    //
    this.watch = function (channel, repo, cb) {
        //regexps user/repo (branch)
        var where = Hash.zip(['user','repo','branch'], repo.match(/([\w\-_]+)/g));
        if (!where.branch) where.branch = 'master';

        //console.log("Watching "+where.user+'/'+where.repo+' ('+where.branch+')');
        //cb(err, data) ?
        //cb(where);

        var key = Hash(where).values.join('/');

        db.get(key, function (err, branch) {
            var b = branch || { channels : [] };
exports['json'] = function (assert) {
    var file = '/tmp/' + Math.floor(Math.random() * 1e8) + '.db';
    
    Store(
        { filename : file, json : true },
        function (error, db) {
            if (error) throw error;
            
            db.set('pkrumins', { age : 25, sex : 'male', location : 'latvia' },
                function (sErr) {
                    assert.ok(!sErr);
                    db.get('pkrumins', function (gErr, value) {
                        assert.ok(!gErr);
                        assert.equal(value.age, 25);
                        assert.equal(value.sex, 'male');
                        assert.equal(value.location, 'latvia');
                    });
                }
            );
            
            db.set('substack', { age : 22, sex : 'male',
                location : { country : 'usa', state : 'alaska' } }, function (sErr) {
                    assert.ok(!sErr);
                    db.get('substack', function (gErr, value) {
                        assert.ok(!gErr);
                        assert.equal(value.age, 22);
                        assert.equal(value.sex, 'male');
                        assert.equal(value.location.country, 'usa');
                        assert.equal(value.location.state, 'alaska');

                        db
                        .on('error', assert.fail)
                        .forEach(function (row) {
                            var key = row.key, val = row.value;
                            assert.ok(key == 'pkrumins' || key == 'substack');
                            assert.ok(val.age == 22 || val.age == 25);
                            assert.ok(val.location == 'latvia' || val.location.country == 'usa');

                            db
                                .filter(function (row) {
                                    return row.value.age <= 22;
                                })
                                .join(function (rows) {
                                    assert.equal(rows.length, 1);
                                    assert.equal(rows[0].key, 'substack');
                                    assert.equal(rows[0].value.age, 22);
                                    
                                    db.all(function (aErr, keys, vals) {
                                        assert.ok(!aErr);
                                        assert.equal(keys.length, 2);
                                        assert.equal(vals.length, 2);
                                        assert.ok('pkrumins' == keys[0] || 'pkrumins' == keys[1]);
                                        assert.ok('substack' == keys[0] || 'substack' == keys[1]);
                                    });
                                })
                            ;
                        })
                    });
                }
            );
        }
    );
};
Exemple #7
0
Store({ filename : __dirname + '/../../data/procs.db', json : true }, function (err, procs) {
    if (err) throw err;

    Hash(module.exports).forEach(function (manager) {
        manager.on('spawn', function (proc) {
            procs.set(
                proc.address,
                Hash.extract(proc, 'address engine filename pid'.split(' ')),
                function (err) { if (err) throw err }
            );
        });
        
        manager.on('connect', function (proc) {
            proc.on('exit', function () {
                procs.remove(
                    proc.address,
                    function (err) { if (err) throw err }
                );
            });
        });
    });

    procs.forEach(function (err, _, proc) {
        console.log('Connecting process ' + proc.pid + ' at ' + proc.address);
        var p = module.exports[proc.engine].connect(proc);
        if (!p) {
            console.log('Removing proccess ' + proc.pid + ' at ' + proc.address);
            procs.remove(
                proc.address,
                function (err) { if (err) throw err }
            );
        }
    });
});