-
Notifications
You must be signed in to change notification settings - Fork 26
/
example.js
37 lines (33 loc) · 1011 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
32
33
34
35
36
/* mysql-live-select, MIT License [email protected]
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 table = 'players';
var id = 11;
liveConnection.select(function(esc, escId){
return (
'select * from ' + escId(table) +
'where `id`=' + esc(id)
);
}, [ {
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);
});