petersirka/nosql

Events not working

g666nz opened this issue · 6 comments

function socket_dash() {

var controller = this;
var nosql = NOSQL('dashboard_ws');
controller.on('open', function(client) {

	console.log('Connect / Online:', controller.online);

	//client.send({ message: 'Hello {0}'.format(client.id) });
});

nosql.on('update', function(client) {
	//controller.send({message: 'this works')};
	console.log("It refresh");
});

}

i have a simple websocket connection. From where i want the nosql event to listen and send data to the client. The nosql database get's update, but the event doesn't execute. The below code is in a model folder and executes just fine. Any idea what i'm doing wrong.

exports.coindesk_cp = function(mod) {
var nosql = NOSQL('dashboard_ws');
nosql.update(mod);
};

Hi @g666nz,
try to install latest beta $ npm install total.js@beta. But important: update event is triggered when the update is really performed.

Give me a feedback.

Hey,
I shall give it a try right now. And get back to you soon.

And what do you mean by "event is triggered when the update is really performed."

exports.coindesk_cp = function(mod) {
var nosql = NOSQL('dashboard_ws');
nosql.update(mod);
};

Is this not fine?

I've tried it, it is not recognising any change in the database.

It works:

require('total.js');

NOSQL('users').on('update', function(doc) {
    console.log('UPDATE EVENT --->', doc);
});

NOSQL('users').insert({ name: 'A' });
NOSQL('users').insert({ name: 'B' });
NOSQL('users').insert({ name: 'C' });
NOSQL('users').insert({ name: 'D' });
NOSQL('users').insert({ name: 'E' });

setTimeout(function() {
    NOSQL('users').update({ name: 'X' }).where('name', 'B');
}, 2000);

setTimeout(function() {
    NOSQL('users').find().callback(function(err, docs) {
        console.log(docs);
    });
}, 4000);

Yes i found my problem, again thank you.