Git Product home page Git Product logo

mysql-events's Introduction

Update:

I haven't been activly updating this code. Others have been activley making updates. Please also checkout their work.

https://github.com/rodrigogs/mysql-events

Note: This version doesn't follow my documentation, so please reference the supplied example code for setup.

https://github.com/rodrigogs/mysql-events/blob/master/examples/watchWholeInstance.js

mysql-events

A Node JS NPM package that watches a MySQL database and runs callbacks on matched events.

This package is based on the ZongJi node module. Please make sure that you meet the requirements described at ZongJi, like MySQL binlog etc.

Quick Start

var MySQLEvents = require('mysql-events');
var dsn = {
  host:     _dbhostname_,
  user:     _dbusername_,
  password: _dbpassword_,
};
var mysqlEventWatcher = MySQLEvents(dsn);
var watcher =mysqlEventWatcher.add(
  'myDB.table.field.value',
  function (oldRow, newRow, event) {
     //row inserted
    if (oldRow === null) {
      //insert code goes here
    }

     //row deleted
    if (newRow === null) {
      //delete code goes here
    }

     //row updated
    if (oldRow !== null && newRow !== null) {
      //update code goes here
    }

    //detailed event information
    //console.log(event)
  }, 
  'match this string or regex'
);

Installation

npm install mysql-events

Usage

  • Import the module into your application
var MySQLEvents = require('mysql-events');
  • Instantiate and create a database connection
var dsn = {
  host:     'localhost',
  user:     'username',
  password: 'password'
};
var myCon = MySQLEvents(dsn);

Make sure the database user has the privilege to read the binlog on database that you want to watch on.

  • Use the returned object to add new watchers
var event1 = myCon.add(
  'dbName.tableName.fieldName.value',
  function (oldRow, newRow, event) {
    //code goes here
  }, 
  'Active'
);

This will listen to any change in the fieldName and if the changed value is equal to Active, then triggers the callback. Passing it 2 arguments. Argument value depends on the event.

  • Insert: oldRow = null, newRow = rowObject
  • Update: oldRow = rowObject, newRow = rowObject
  • Delete: oldRow = rowObject, newRow = null

rowObject

It has the following structure:

{
  database: dbName,
  table: tableName,
  affectedColumns: {
    [{
      name:     fieldName1,
      charset:  String,
      type:     Number
      metedata: String
    },{
      name:     fieldName2,
      charset:  String,
      type:     Number
      metedata: String
    }]
},{
  changedColumns: [fieldName1, fieldName2],
  fields: {
   fieldName1: recordValue1,
   fieldName2: recordValue2,
     ....
     ....
     ....
   fieldNameN: recordValueN
  }
}

Remove an event

event1.remove();

Stop all events on the connection

myCon.stop();

Additional options

In order to customize the connection options, you can provide your own settings passing a second argument object to the connection function.

var mysqlEventWatcher = MySQLEvents(dsn, {
  startAtEnd: false // it overrides default value "true"
});

You can find the list of the available options here.

Watcher Setup

Its basically a dot '.' seperated string. It can have the following combinations

  • database: watches the whole database for changes (insert/update/delete). Which table and row are affected can be inspected from the oldRow & newRow
  • database.table: watches the whole table for changes. Which rows are affected can be inspected from the oldRow & newRow
  • database.table.column: watches for changes in the column. Which database, table & other changed columns can be inspected from the oldRow & newRow
  • database.table.column.value: watches for changes in the column and only trigger the callback if the changed value is equal to the 3rd argument passed to the add().
  • database.table.column.regexp: watches for changes in the column and only trigger the callback if the changed value passes a regular expression test to the 3rd argument passed to the add(). The 3rd argument must be a Javascript Regular Expression Object, like, if you want to match for a starting sting (eg: MySQL) in the value, use /MySQL/i. This will trigger the callback only if the new value starts with MySQL

LICENSE

MIT

mysql-events's People

Contributors

datatraders avatar jfbueno avatar jonathanargentiero avatar pschuster avatar sirhanshafahath avatar spencerlambert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mysql-events's Issues

Not working with multiple application with.

Hi,

I have two applications with nodejs, actually version 1 and version 2.

When I start two applications at the same time, the mysql-evetns not working properly.

I created database replication user for each applications for event watching, but event logs wrote only one of application.

Is it possible that run multiple applications for mysql-events at the same time?

the connection is not get establishing ?

Here the code which I am using for auto notifying if there is any change in mySql database to nodeJS, it dosn't notifying?, at the same time I have edited my.cnf file and GRANT privilages to the user too

my.cnf file

binlog_format = row
log_bin         = /var/log/mysql/mysql-bin.log
binlog_do_db     = test   # Optional, limit which databases to log

nodeJS

var MySQLEvents = require('mysql-events');
var dsn = {
host: 'localhost',
user: 'root',
password: 'root',
};
var mysqlEventWatcher = MySQLEvents(dsn);
console.log(mysqlEventWatcher); // connection is disconnect
var watcher = mysqlEventWatcher.add(
'test.eventTable',
function (oldRow, newRow) {
//row inserted
console.log(oldRow);
console.log('_');
console.log(newRow);
console.log('_
');
if (oldRow === null) {
//insert code goes here
}
//row deleted
if (newRow === null) {
//delete code goes here
}
//row updated
if (oldRow !== null && newRow !== null) {
//update code goes here
}
},
'Active'
);

while console the connection :

var mysqlEventWatcher = MySQLEvents(dsn);
console.log(mysqlEventWatcher); // connection is disconnect

{ started: false,
zongji:
ZongJi {
options: {},
domain: null,
_events: { error: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
ctrlConnection:
Connection {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
config: [Object],
_socket: [Object],
_protocol: [Object],
_connectCalled: true,
state: 'disconnected',
threadId: null },
ctrlCallbacks: [],
connection:
Connection {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
config: [Object],
_socket: undefined,
_protocol: [Object],
_connectCalled: false,
state: 'disconnected',
threadId: null },
tableMap: {},
ready: false,
useChecksum: false },
databases: [],
tables: {},
columns: {},
events: [ 'tablemap', 'writerows', 'updaterows', 'deleterows' ],
triggers: [],
connect: [Function],
add: [Function],
remove: [Function],
stop: [Function],
reload: [Function],
includeSchema: [Function] }

More than one .add not working correctly

When you create many "watchers" to different tables (with add()), the first watched table works correctly but the other ones stop to work after around 10 minutes.

var MySQLEvents = require('mysql-events');
var mysqlEventWatcher = MySQLEvents({host: 'localhost', user: 'XXX', password: 'YYY'});
var DB = require('./db.js');
var myDB = DB.connection;
...
var watcherEmployees = mysqlEventWatcher.add(
  'db.employees',....
)
var watcherAccounts = mysqlEventWatcher.add(
  'db.accounts',....
)
var watcherBills = mysqlEventWatcher.add(
  'db.bills',....
)

The changes on employees table are always catched, independently of the time there is no action on the table.
The changes on accounts and bills tables are not catched anymore if there is no change for around 10 minutes.

If the order of mysqlEventWatcher.add is changed, then it's always the first table watcher who keep working.

There isn't a difference between the update and delete

Hi, I was reading the docs and the docs say that the delete should have the newRow === null but here is the dump from a delete. I'm using "mysql-events" : "0.0.7" (I just did a npm install mysql-events --save). I really need this to work and I appreciate any help you can provide. Thanks!

{ database: 'fusion',
  table: 'assets',
  affectedColumns: 
   [ { name: 'id', charset: null, type: 3, metadata: undefined },
     { name: 'timestamp', charset: null, type: 7, metadata: undefined },
     { name: 'name', charset: 'latin1', type: 15, metadata: [Object] },
     { name: 'description',
       charset: 'latin1',
       type: 252,
       metadata: [Object] },
     { name: 'customer_id',
       charset: null,
       type: 3,
       metadata: undefined },
     { name: 'owner_id', charset: null, type: 3, metadata: undefined },
     { name: 'type_id', charset: null, type: 3, metadata: undefined },
     { name: 'status_id', charset: null, type: 3, metadata: undefined },
     { name: 'visible', charset: null, type: 2, metadata: undefined },
     { name: 'make', charset: 'latin1', type: 15, metadata: [Object] },
     { name: 'model', charset: 'latin1', type: 15, metadata: [Object] },
     { name: 'year', charset: null, type: 3, metadata: undefined },
     { name: 'vin', charset: 'latin1', type: 15, metadata: [Object] },
     { name: 'requirements',
       charset: 'latin1',
       type: 252,
       metadata: [Object] },
     { name: 'latitude',
       charset: 'latin1',
       type: 15,
       metadata: [Object] },
     { name: 'longitude',
       charset: 'latin1',
       type: 15,
       metadata: [Object] },
     { name: 'gps_timestamp',
       charset: null,
       type: 7,
       metadata: undefined },
     { name: 'gps_bearing',
       charset: 'latin1',
       type: 15,
       metadata: [Object] },
     { name: 'gps_speed',
       charset: 'latin1',
       type: 15,
       metadata: [Object] },
     { name: 'accounting_ref',
       charset: 'latin1',
       type: 15,
       metadata: [Object] } ],
  changedColumns: [ 'timestamp', 'visible', 'gps_timestamp' ],
  fields: 
   { id: 3,
     timestamp: Mon Mar 21 2016 12:29:36 GMT-0600 (MDT),
     name: 'DG4',
     description: '53gh',
     customer_id: 1000,
     owner_id: 1000,
     type_id: 5,
     status_id: null,
     visible: 1,
     make: 'dh',
     model: 'fdh',
     year: 0,
     vin: 'g54e',
     requirements: null,
     latitude: null,
     longitude: null,
     gps_timestamp: Wed Dec 31 1969 17:00:00 GMT-0700 (MST),
     gps_bearing: null,
     gps_speed: null,
     accounting_ref: null } }
{ database: 'fusion',
  table: 'assets',
  affectedColumns: 
   [ { name: 'id', charset: null, type: 3, metadata: undefined },
     { name: 'timestamp', charset: null, type: 7, metadata: undefined },
     { name: 'name', charset: 'latin1', type: 15, metadata: [Object] },
     { name: 'description',
       charset: 'latin1',
       type: 252,
       metadata: [Object] },
     { name: 'customer_id',
       charset: null,
       type: 3,
       metadata: undefined },
     { name: 'owner_id', charset: null, type: 3, metadata: undefined },
     { name: 'type_id', charset: null, type: 3, metadata: undefined },
     { name: 'status_id', charset: null, type: 3, metadata: undefined },
     { name: 'visible', charset: null, type: 2, metadata: undefined },
     { name: 'make', charset: 'latin1', type: 15, metadata: [Object] },
     { name: 'model', charset: 'latin1', type: 15, metadata: [Object] },
     { name: 'year', charset: null, type: 3, metadata: undefined },
     { name: 'vin', charset: 'latin1', type: 15, metadata: [Object] },
     { name: 'requirements',
       charset: 'latin1',
       type: 252,
       metadata: [Object] },
     { name: 'latitude',
       charset: 'latin1',
       type: 15,
       metadata: [Object] },
     { name: 'longitude',
       charset: 'latin1',
       type: 15,
       metadata: [Object] },
     { name: 'gps_timestamp',
       charset: null,
       type: 7,
       metadata: undefined },
     { name: 'gps_bearing',
       charset: 'latin1',
       type: 15,
       metadata: [Object] },
     { name: 'gps_speed',
       charset: 'latin1',
       type: 15,
       metadata: [Object] },
     { name: 'accounting_ref',
       charset: 'latin1',
       type: 15,
       metadata: [Object] } ],
  changedColumns: [ 'timestamp', 'visible', 'gps_timestamp' ],
  fields: 
   { id: 3,
     timestamp: Mon Mar 21 2016 12:31:01 GMT-0600 (MDT),
     name: 'DG4',
     description: '53gh',
     customer_id: 1000,
     owner_id: 1000,
     type_id: 5,
     status_id: null,
     visible: 0,
     make: 'dh',
     model: 'fdh',
     year: 0,
     vin: 'g54e',
     requirements: null,
     latitude: null,
     longitude: null,
     gps_timestamp: Wed Dec 31 1969 17:00:00 GMT-0700 (MST),
     gps_bearing: null,
     gps_speed: null,
     accounting_ref: null } }

It seems connections is never destroyed zongji.on('error') is called

In index.js, if on 'error' is triggered, it seems recursively calling zongjiManager will new ZongJi every time and that seems to cause infinite connections.

Upon creating ZongJi, new connections to db are created and it does not seem to me they are destroyed or released properly?

function zongjiManager(dsn, options, onBinlog) {
var newInst = new ZongJi(dsn, options);
newInst.on('error', function(reason) {
newInst.removeListener('binlog', onBinlog);
newInst.child = false;
setTimeout(function() {
// If multiple errors happened, a new instance may have already been created
if(!newInst.child) {
var newInstNext = zongjiManager(dsn, Object.assign({}, options, newInst.binlogNextPos

Error in list of changedColumns (for columns of type datetime) in update

if the obj1 = obj2, the comparison (obj1 != obj2) return true in JS

and because the code return column(of type datetime) as object
typeof(row.fields.column) === "object" , and we have a problem in comparison
it's add the column name (of type datetime) to changedColumns

you can solve this issue by checking the type of column before comparison or convert object to string

example add before :
https://github.com/spencerlambert/mysql-events/blob/master/index.js#L162
this code :
if(typeof(row.before[key]) === "object") row.before[key] = JSON.stringify(row.before[key]);
if(typeof(row.after[key]) === "object") row.after[key] = JSON.stringify(row.after[key]);

you can read this :
https://stackoverflow.com/questions/1068834/object-comparison-in-javascript

thank you

ER_MASTER_FATAL_ERROR_READING_BINLOG error when restart on zongji.on('error') is called

setTimeout(function() {
if(!newInst.child) {
console.log("dbWarcher error restart ZJ:")
var newInstNext = zongjiManager(dsn, options, onBinlog);
newInst.stop();
newInst = newInstNext;
newInst.child = true;
}
}, RETRY_TIMEOUT);

if database changed in "RETRY_TIMEOUT" time, restart zongji will case "ER_MASTER_FATAL_ERROR_READING_BINLOG: ".

full error message:

{ Error: ER_MASTER_FATAL_ERROR_READING_BINLOG: Client requested master to start replication from position > file size; the first event '' at 465694, the last event read from '/home/mysql/data3067/mysql/mysql-bin.000433' at 4, the last byte read from '/home/mysql/data3067/mysql/mysql-bin.000433' at 4

Connect through ssh tunnel

I love this project, thanks for the good work. But how could I use mysql-events with a database that is only reachable through an ssh tunnel using a certificate?

Events are not triggering if the database having period symbol (.)

HI All,

I am having database name called "employee.qa" and when I used table like below to monitor and it is not trigger.

var category_table = 'employee.qa.tablename';
var category = mysqlEventWatcher.add(
category_table,
function (oldRow, newRow, event) {
console.log("Category Event Watcher Called ");



But the above code working fine if i use database employee_qa. Can you please let me know is there any work around with period symbol. I tried below ways
var category_table = 'employee.qa.tablename';
var category_table = '[employee.qa].tablename';
var category_table = ''employee.qa'.tablename';
var category_table = ''employee.qa'.tablename';

Thanks in advance

Zongji retrieves full binlog when being reinstantiated

A customer was complaining that his chat application was not getting updates from mysql-events. I looked into it and found out the following:

  1. After some idle time, mysql (mariadb) drops the connection created by Zongji.
  2. mysql-events correctly catches the error and instantiates Zongji again
  3. The new instance of Zongji appears to ask for the full binlog from the db, which in this particular case exceeds max_allowed_packet. Zongji therefore crashes going back to point (2)

All of this happens in the background, as no error is emitted...

To solve this, I changed lines 17-22 from :

var newInstNext = zongjiManager(dsn, Object.assign({}, options, newInst.binlogNextPos
        	 ? {  binlogName: newInst.binlogName,
               	 binlogNextPos: newInst.binlogNextPos
      	      }
     	    : {}
), onBinlog);

to

var newInstNext = zongjiManager(dsn, options, onBinlog);

This works as options contains startAtEnd. Zongji therefore doesn't get the full binlog. But it's also an ugly hack, as there is a chance of missing some events.

I still need to investigate deeper and determine if the problem lies in the binlogName / binlogNextPos variables or if the problem lies within Zongji. Just wanted to get this out in case somebody has some comments.

Nothing seems to happen

Hi i'm new to node, and i'm trying to make you module work. However, nothing happens when i insert in my database, or even if i update or delete. I hope you can help me. here's my full code:
`
var MySQLEvents = require('mysql-events');

var dsn = {
host: "localhost",
user: "root",
password: "mypassword",
};

var myCon = MySQLEvents(dsn);

var event1 = myCon.add(

'test.foo.name.value',

function (oldRow, newRow) {

console.log("test");

},

'Active'

);

`
Thanks a lot

EDIT: btw, i tried by inserting "Active" in the column "name" of the table "foo", and alose by updating another row!

Update to Zongji 0.4.3

Hi,

i have testet the code with Zongji 0.4.3 and it run without errors.

Can you please update the npm package with the new Zongji version?

Not getting myslq events

Hi,

I have followed your step and the node server is running and listening, but mysql event not working. It is not listening the mysql event when i insert or update the record.

Here is my server.js code :

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io').listen(http);
// var Redis = require('redis');
var mysql = require('mysql');
var MySQLEvents = require('mysql-events');

var dsn = {
host: 'localhost',
user: 'root',
password: 'DEVtrushield@123'
};

http.listen(3000, function(){
console.log('Listening on Port 3000');
});

io.sockets.on('connection', function (socket) {
socket.emit('welcome', { hello: 'world' });

socket.on('mysql', function (data) {
	
	// console.log(data);

	// var connection = mysql.createConnection({
	//     host: 'localhost',
	//     port: 3306,
	//     user: 'root',
	//     password: 'DEVtrushield@123',
	//     database: 'ts_tintel'
	// });

	var myCon = MySQLEvents(dsn);

	var event1 = myCon.add(
	  'ts_tintel.ts_intel_last_hour_datas.lasthourdataid.value',
	  function (oldRow, newRow) {
	    console.log(oldRow);
	    console.log(newRow);
	    console.log("================================================================================");
	  }, 
	  'Active'
	);

});
});

Please tell me where i have done mistake.

Error: Connection lost: The server closed the connection.

Hi Team,

The following bug has been came when update the table data.

events.js:141
throw er; // Unhandled 'error' event
^

Error: Connection lost: The server closed the connection.
at Protocol.end (D:\examples\mysqlwatch\node_modules\mysql-events\node_modules\zongji\node_modules\mysql\lib\protocol\Protocol.js:103:13)
at Socket. (D:\examples\mysqlwatch\node_modules\mysql-events\node_modules\zongji\node_modules\mysql\lib\Connection.js:88:28)
at emitNone (events.js:72:20)
at Socket.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:893:12)
at doNTCallback2 (node.js:429:9)
at process._tickCallback (node.js:343:17)

Nothing's happening...

I'm using zwamp for coding on the move and it has normal mysql.
I don't get any error in the console..

my code

var dsn = {
    host: 'localhost',
    user: 'root',
    password: '',
};
var mysqlEventWatcher = mysqlevents(dsn);
var watcher = mysqlEventWatcher.add(
  'skinpay.payments',
  function (oldRow, newRow) {
      //row inserted
    console.log("New row inserted!");
    if (oldRow === null) {
      //insert code goes here 
    }

     //row deleted 
    if (newRow === null) {
      //delete code goes here 
    }

     //row updated 
    if (oldRow !== null && newRow !== null) {
      //update code goes here 
    }
  }, 
  'match this string or regex'
);

It should print something in the console if I insert something manually, right?

Looking for quick help.

Listens to multiple changes?

I just want to double check if mysql-events supports monitoring multiple changes? For example, what happens if I do bulk insert/delete/update to the tables?

Inconsisten fields and values

I realized that if you console.log (newRow.fields), the fields are listed in alphabetical order while values ​​are listed in order that it were created.

Cannot read property 'host' of undefined

Whenever I tried to console mysqlEventWatcher.coonect(), it throws the following error

if (!_underScore.isUndefined(dsn.host) &&
^
TypeError: Cannot read property 'host' of undefined
at Object.connect (/Public_Nodejs/node_modules/mysql-events/index.js:64:39)

But I defined my dsn object.

Here is my dsn object

var db_config = {
host : 'localhost',
user : 'root',
password : 'password',
}

var MySQLEvents = require('mysql-events');
var dsn = {
host: db_config.host,
user: db_config.user,
password: db_config.password
};

var mysqlEventWatcher = MySQLEvents(dsn);
console.log(mysqlEventWatcher);

console.log('Before SqlWatcher');

var watcher =mysqlEventWatcher.add(
'mydb.mttable1',
// 'myDB.table.field.value',
function (oldRow, newRow, event) {
console.log('Hello'+'i am in sqlWatcher');
//row inserted
if (oldRow === null) {
//console('insert code goes here');
}

 //row deleted
if (newRow === null) {
  //delete code goes here
}

 //row updated
if (oldRow !== null && newRow !== null) {
  //update code goes here
}

//detailed event information
console.log(event)

},
'Active'
);

Cannot read property 'COLUMN_NAME' of undefined

I'm running this application and got the error:

require('dotenv').config()

var MySQLEvents = require('mysql-events');
var cors = require('cors')
var app = require('express')();
app.use(cors);
var http = require('http').Server(app);

var io = require('socket.io')(http, {
  origins: '*:*'
});
var dsn = {
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
};
var mysqlEventWatcher = MySQLEvents(dsn);
http.listen(3000, function() {
  console.log('Escutando porta:3000');
});
io.on('connection', function(socket) {

  console.log("Conexao via socket");
  var watcher = mysqlEventWatcher.add(
    'database.table',
    function(oldRow, newRow) {
      //row inserted
      if (oldRow === null) {
        io.emit('data', newRow);
      }

      //row deleted
      if (newRow === null) {
        //delete code goes here
      }

      //row updated
      if (oldRow !== null && newRow !== null) {
        //update code goes here
      }
    },
    'match this string or regex'
  );
  socket.on('disconnect', function() {
    console.log("Desconectou");
  });

});
c:\Users\felipe\Desktop\mysql event\node_modules\mysql\lib\protocol\Parser.js:82
        throw err;
        ^

TypeError: Cannot read property 'COLUMN_NAME' of undefined
    at TableMap.updateColumnInfo (c:\Users\felipe\Desktop\mysql event\node_modules\zongji\lib\binlog_event.js:164:29)
    at c:\Users\felipe\Desktop\mysql event\node_modules\zongji\index.js:185:19
    at Query._callback (c:\Users\felipe\Desktop\mysql event\node_modules\zongji\index.js:159:5)
    at Query.Sequence.end (c:\Users\felipe\Desktop\mysql event\node_modules\mysql\lib\protocol\sequences\Sequence.js:96:24)
    at Query._handleFinalResultPacket (c:\Users\felipe\Desktop\mysql event\node_modules\mysql\lib\protocol\sequences\Query.js:143:8)
    at Query.EofPacket (c:\Users\felipe\Desktop\mysql event\node_modules\mysql\lib\protocol\sequences\Query.js:127:8)
    at Protocol._parsePacket (c:\Users\felipe\Desktop\mysql event\node_modules\mysql\lib\protocol\Protocol.js:271:23)
    at Parser.write (c:\Users\felipe\Desktop\mysql event\node_modules\mysql\lib\protocol\Parser.js:77:12)
    at Protocol.write (c:\Users\felipe\Desktop\mysql event\node_modules\mysql\lib\protocol\Protocol.js:39:16)
    at Socket.<anonymous> (c:\Users\felipe\Desktop\mysql event\node_modules\mysql\lib\Connection.js:82:28)

Losing mysql connection without any message

After being able to watch events for a while, the events stop being triggered after ~10 mins.
I am assuming that the connection to the database was lost, but I'm not sure as there is no error thrown or anything..
I read on this thread #32 something similar but no solution there.
If I activate the debug option on the dsn settings, I see plenty of logs while the binlog is updated, but it just stops after a while without showing any error.
Is there a way of activating a more verbose version of mysql-events to see what is really happening?

Monitoring MySQL database for specific column is not working

I have been using MySQL database to monitor specific column of table. It does not capture any changes that happens in the database.
My Code :

var eventObj = conObj.add(data.monitor_path, function(oldData, newData) {
console.log(oldData);
console.log(newData);

}, 'Active');

can you please let me know what i am missing.?

Thanks.

Fields changing order

The fields (RecNum, TmStamp) in my newRow object just changed order,
Used to be:
fields:
{ RecNum: 36290117,
TmStamp: 2019-03-29T13:01:09.000Z,
VH_mps: 1.5679999589920044,
VR_grader: 199 }
Now it has the timestamp in the RecNum instead:
fields:
{ RecNum: 2019-03-29T13:01:09.000Z,
TmStamp: 36290117,
VH_mps: 1.5679999589920044,
VR_grader: 199 }

The new rows in the database is as they should be, the code is as the readme describes. My application doesn't work now, I can't just rewrite RecNum being the DATETIME. What if it goes back? Any idea what happend here or how to fix this?

Not able to synchronized the events.

Hi,

I am able to receive the events when these events are in 1 second 1 event only, but when i am receiving 100 events per second then nothing is showing due to the volume.

I there any way to sync or do the locking kind of thing like we do the same in any programming language.

SyntaxError: Unexpected token >

I'm getting the following error when I execute the example from the Quick Start:

................/node_modules/mysql-events/index.js:20
newInst.child.on('child', child => newInst.emit('child

SyntaxError: Unexpected token >
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (.............../client.js:4:19)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)

Am I doing something wrong here?

Current binlog position

Hi,

I'm using

mysql-events version 0.0.8
zongji version 0.4.3

I'm wondering if there is a way to get the current binlog and position when the event fires? I thought the properties zongji.binlogName and zongji.binlogNewPosition would give this but this doesn't seem to be the case. I'd like to make sure that if the application needs to restart that I can start where it left off.

Do I have to issue a Show Master command on the server each time I see an event I'm interested in?

Any help gratefully received,
Al.

Listening to a specific column

Hello,

I try to listen a specific column but I can't manage to make it work. It works fine when I only listen to a database or a table, tough. Here is my code :

`var MySQLEvents = require('mysql-events');
var dsn = {
host: 'localhost',
user: '_',
password: '
_
',
};
var mysqlEventWatcher = MySQLEvents(dsn);

//Fires when a match is started
var newMatchStarted =mysqlEventWatcher.add(
'bot.matchs.status',
function (oldRow, newRow) {
console.log(newRow);
console.log(oldRow);
}
);`

Thanks a lot!

uncomment the line in index.js

in index.js line below


this.zongji.on('error', function(err) {
//console.log("ZongJi error event", err);
});


the commented line should be uncommented.
1.With out it it does not capture the 'error' event.
2.Cause of 'No event notifications' #23 is also due to this because 'Error: Received packet in the wrong sequence' is not caught by this line causing further issues.
3. Because the 'error' event is bypassed without notification and actually is not made, so the
'var watcher = mysqlEventWatcher.add(arg,handler)' is not listening also that's why causing 'no event notification' bug.

No event notifications

Hi - I am trying to use the mysql-events and I am not getting any event notifications. Having gone through all issues - I have created the replication user and the my.cnf files entries .
My code is as below :

var MySQLEvents = require('mysql-events');

//awesome change
var dsn = {
host: 'localhost',
user: 'myuser',
password: 'password'
};
var mysqlEventWatcher = MySQLEvents(dsn);
console.log(mysqlEventWatcher);
var watcher = mysqlEventWatcher.add('test.employee.name.value',
function (oldRow, newRow) {
console.log(oldRow);
console.log(newRow);
console.log("================================================================================");
},'Active'
);
By the below logs , it looks like zongji itself isnt working , can you please help with possible issue ?
I am using MAC and mysql 5.7.17.
{ started: false,
zongji: {},
databases: [],
tables: {},
columns: {},
events: [ 'tablemap', 'writerows', 'updaterows', 'deleterows' ],
triggers: [],
dsn: { host: 'localhost', user: 'myuser', password: 'password' },
settings: {},
connect: [Function: connect],
add: [Function: add],
remove: [Function: remove],
stop: [Function: stop],
reload: [Function: reload],
includeSchema: [Function: includeSchema] }

Multi table Watcher with MysqlEvents ?

Hi guys,
Happy New Year 2018

Can i listen multi table with MysqlEvent ?

let watcher =mysqlEventWatcher.add(
'database.tablesname',
...

I would add a second tables , how to do this ?

thx

RangeError: Maximum call stack size exceeded

mysql-events version 0.0.8
zongji version 0.4.3

Experienced the unhandled exception error with mysql-events 0.0.7 when the MySQL database closed the connection so I updated to the latest version. Ran my node.js script overnight (since the error always occurred 8 hours after the last database transaction) to see if the solution was fixed and encountered this error:

C:\wamp64\www\ldnpush\node_modules\mysql-events\index.js:20
newInst.child.on('child', child => newInst.emit('child', child));
(this arrow points at "emit")---------------^

RangeError: Maximum call stack size exceeded
at ZongJi. (C:\wamp64\www\ldnpush\node_modules\mysql-events\index.js:20:68)
at emitOne (events.js:77:13)
at ZongJi.emit (events.js:169:7)
at ZongJi. (C:\wamp64\www\ldnpush\node_modules\mysql-events\index.js:20:68)
at emitOne (events.js:77:13)
at ZongJi.emit (events.js:169:7)
at ZongJi. (C:\wamp64\www\ldnpush\node_modules\mysql-events\index.js:20:68)
at emitOne (events.js:77:13)
at ZongJi.emit (events.js:169:7)
at ZongJi. (C:\wamp64\www\ldnpush\node_modules\mysql-events\index.js:20:68)

reconnect to mysql when disconnected...

Is there a way to detect if I am still connected to mysql and then reconnect if so?

I am using this library to update a firebase live db with information to use in an app. It seems around ~8-9 hours the updates just halt with no errors at all. I can only assume it is, for some reason, disconnecting from the mysqldb.

My initial thought is to run a cronjob every 7hr 55min or so to restart the nodejs app service.

I have a couple things that could be messed up by this even though the restart will be about 1 second long it can potentially cause issues every once in a while so I want to see about just reconnecting once it is disconnected.

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.