Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

old row new row, urgent #30

Open
CrazyBunnyz opened this issue Nov 7, 2020 · 3 comments
Open

old row new row, urgent #30

CrazyBunnyz opened this issue Nov 7, 2020 · 3 comments

Comments

@CrazyBunnyz
Copy link

CrazyBunnyz commented Nov 7, 2020

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

@CrazyBunnyz CrazyBunnyz changed the title old row new row old row new row, urgent Nov 7, 2020
@Kayoti
Copy link

Kayoti commented May 21, 2021

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
Copy link

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
Copy link

@felippelmartins Hi. Does this problem resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants