forked from wj32/mysql-live-select
-
Notifications
You must be signed in to change notification settings - Fork 8
/
example.js
31 lines (28 loc) · 956 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* mysql-live-select, MIT License ben@latenightsketches.com
example.js - Use mysql < example.sql to get started */
var LiveMysql = require('./');
var settings = {
host : 'localhost',
user : 'root',
password : 'numtel',
database : 'leaderboard',
serverId : 34,
minInterval : 200
};
var liveConnection = new LiveMysql(settings);
var id = 11;
liveConnection.select('select * from players where `id` = ?', [id],
LiveMysqlKeySelector.Index(), [ {
table: table,
condition: function(row, newRow){
// Only refresh the results when the row matching the specified id is
// changed.
return row.id === id
// On UPDATE queries, newRow must be checked as well
|| (newRow && newRow.id === id);
}
} ]).on('update', function(diff, data){
// diff contains an object describing the difference since the previous update
// data contains an array of rows of the new result set
console.log(data);
});