rodrigogs / mysql-events

A node package that watches a MySQL database and runs callbacks on matched events.
BSD 3-Clause "New" or "Revised" License
136 stars 52 forks source link

old row new row, urgent #30

Open CrazyBunnyz opened 3 years ago

CrazyBunnyz commented 3 years ago

i would like to get old row and new row like https://www.npmjs.com/package/mysql-events. right now all i got is IntVar { timestamp: 1604743109000, nextPosition: 4795, size: 9, type: 2, value: 17, binlogName: 'mysql-bin.000001' } basically i want more detail. can you help me ? and it doesnt detect update too. here is my code const mysql = require('mysql'); const MySQLEvents = require('@rodrigogs/mysql-events');

const program = async () => { const connection = mysql.createConnection({ host: 'localhost', user: 'root', password: '', database: 'sociominer' });

const instance = new MySQLEvents(connection, { startAtEnd: true, excludedSchemas: { mysql: true, }, });

await instance.start();

instance.addTrigger({ name: 'TEST', expression: '*', statement: MySQLEvents.STATEMENTS.ALL, onEvent: (event) => { console.log(event); // { type, schema, table, affectedRows: [], affectedColumns: [], timestamp, } }, });

instance.on(MySQLEvents.EVENTS.CONNECTION_ERROR, console.error); instance.on(MySQLEvents.EVENTS.ZONGJI_ERROR, console.error); };

program() .then(() => console.log('Waiting for database events...')) .catch(console.error);

and db image

i just want to see if there are insert update delete event from test table ( only test table ) and coresponding old row and new row and what about if i want to listen specificly to certain table only cause currently i listen to al table. already try expression: '*.test', but no event comming instead ( no event ) note : i never and dont want to use schema if possible my aim is really similar to this https://github.com/kuroski/mysql-events-ui/blob/master/server.js except i need to know which table and row inserted and updated so i know which client shoud i emitted to. especially on insert and update

Kayoti commented 3 years ago

you just simply need to traverse the log by calling the right event and traverse the array "e.affectedRows['0']" remember if you have "startAtEnd: true" flag set to true you will not see the output until you actually trigger an event , if you want to view all existing events so that you can debug and traverse without triggering an event set it to false

instance.addTrigger({
    name: 'monitoring all statments',
    expression: 'test.testtable.*', 
    statement: MySQLEvents.STATEMENTS.ALL, 
    onEvent: e => {

      console.log(e.affectedRows['0']['before']);
      console.log(e.affectedRows['0']['after']);

    }
  });
felippelmartins commented 3 years ago

My problem is similar to CrazyBunnyz's The event does not show all the info and the expression does not work unless I put only '*'. My output is similar: IntVar { timestamp: 1622029530000, nextPosition: 715, size: 9, type: 2, value: 8, binlogName: 'mysql-bin-changelog.000188' }

olivinesguerra commented 1 year ago

@felippelmartins Hi. Does this problem resolved?