我正在使用mysql-events创建一个节点应用程序进行测试,它的工作方式与预期有所不同,但我的代码执行不正常,除非我将var MySQLEvents = require('mysql-events');
var dsn = {
host: 'localhost',
user: 'root',
password: ''
};
var myCon = MySQLEvents(dsn);
var event1 = myCon.add(
'db.test.name.value',
function (oldRow, newRow, event) {
if (oldRow !== null && newRow !== null) {
console.log("DB change")
}
},
'Active'
);
var MySQLEvents = require('mysql-events');
var dsn = {
host: 'localhost',
user: 'root',
password: '',
};
var mysqlEventWatcher = MySQLEvents(dsn);
var watcher =mysqlEventWatcher.add(
'experimental.test',
function (oldRow, newRow, event) {
//row inserted
if (oldRow === null) {
console.log("Row inserted");
}
//row deleted
if (newRow === null) {
console.log("Row deleted");
}
//row updated
if (oldRow !== null && newRow !== null) {
console.log("Row updated");
}
//detailed event information
//console.log(event);
},
);
添加到脚本中。?
当我更改数据库时,此代码不输出任何内容:
console.log
此代码输出适当的var MySQLEvents = require('mysql-events');
var dsn = {
host: 'localhost',
user: 'root',
password: ''
};
var myCon = MySQLEvents(dsn);
var event1 = myCon.add(
'db.test.name.value',
function (oldRow, newRow, event) {
if (oldRow !== null && newRow !== null) {
console.log("DB change")
}
},
'Active'
);
var MySQLEvents = require('mysql-events');
var dsn = {
host: 'localhost',
user: 'root',
password: '',
};
var mysqlEventWatcher = MySQLEvents(dsn);
var watcher =mysqlEventWatcher.add(
'experimental.test',
function (oldRow, newRow, event) {
//row inserted
if (oldRow === null) {
console.log("Row inserted");
}
//row deleted
if (newRow === null) {
console.log("Row deleted");
}
//row updated
if (oldRow !== null && newRow !== null) {
console.log("Row updated");
}
//detailed event information
console.log(event);
},
);
:
console.log(event);
唯一的区别是脚本底部的第一个代码块module.exports.Time = Math.floor(Date.now() / 1000);
被注释掉了,但它不在第二个。这是为什么?