如何将新更新的行发送到Node.js中的客户端

目前我正在使用Node.js + MySQL POC,它的工作非常好,现在…更新或添加的行将自动通知所有连接到套接字端口的客户端。 但我觉得有必要发送所有的行(让我们说100 +)所有的客户端,因为它是没有任何意义的 – 是否有node.js中的任何模块,从MySQL的新插入或更新行发送广播它的客户? 或者忽略已经传输给客户端的行/数据?

谢谢。

io.sockets.on( 'connection', function ( socket ) { console.log('Number of connections:' + connectionsArray.length); if (!connectionsArray.length) { pollingLoop(); } socket.on('disconnect', function () { var socketIndex = connectionsArray.indexOf( socket ); console.log('socket = ' + socketIndex + ' disconnected'); if (socketIndex >= 0) { connectionsArray.splice( socketIndex, 1 ); } }); console.log( 'A new socket is connected!' ); connectionsArray.push( socket ); }); var updateSockets = function ( data ) { data.time = new Date(); connectionsArray.forEach(function( tmpSocket ){ tmpSocket.volatile.emit( 'notification' , data ); }); }; 

目前上面的代码发送所有的数据到客户端。 只是想知道select逻辑发送只有新的或更新的一个想法。

MySQL连接代码

 mysql = require('mysql'), connectionsArray = [], connection = mysql.createConnection({ host : 'localhost', user : 'root', password : 'root', database : 'nodejs', port : 3306 }), POLLING_INTERVAL = 3000, pollingTimer; // If there is an error connecting to the database connection.connect(function(err) { // connected! (unless `err` is set) console.log( err ); }); 

这是我如何select行 –

 var query = connection.query('SELECT * FROM users')