0

我正在创建一个带有 mysql-events 的节点应用程序进行测试,它按预期工作,但我的代码无法正常执行,除非我添加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);被注释掉了,但它不在第二个代码块中。为什么是这样?

4

0 回答 0