I am creating a node app with mysql-events for testing, it works somewhat as expected but my code is not executing properly unless i add console.log(event);
to the script..?
This code outputs nothing when I change my database:
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);
},
);
This code outputs the appropiate 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);
},
);
The only difference is at the bottom of the script where in the first code block console.log(event);
is commented out, but it is not in the second. Why is this?