我正在用mysql事件创建一个节点应用程序进行测试,它在某种程度上可以正常工作,但是除非添加 console.log(event);
对剧本。。?
当我更改数据库时,此代码不输出任何内容:
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);
已注解掉,但不在第二个中。为什么会这样?
暂无答案!
目前还没有任何答案,快来回答吧!