Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. var MySQLEvents = require('mysql-events');
  2. var dsn = {
  3. host: 'localhost',
  4. user: 'root',
  5. password: '' // no password set that's why keep blank
  6. };
  7. var mysqlEventWatcher = MySQLEvents(dsn);
  8. console.log(mysqlEventWatcher);
  9. var watcher =mysqlEventWatcher.add(
  10. 'myDB.myTable',
  11. function (oldRow, newRow, event) {
  12. //row inserted
  13. if (oldRow === null) {
  14. //insert code goes here
  15. }
  16.  
  17. //row deleted
  18. if (newRow === null) {
  19. //delete code goes here
  20. }
  21.  
  22. //row updated
  23. if (oldRow !== null && newRow !== null) {
  24. //update code goes here
  25. }
  26.  
  27. //detailed event information
  28. console.log(event); // don't matter, it updates, delete or insert
  29. },
  30. 'Active'
  31. );
  32.  
  33. { started: false,
  34. zongji: {},
  35. databases: [],
  36. tables: {},
  37. columns: {},
  38. events: [ 'tablemap', 'writerows', 'updaterows', 'deleterows' ],
  39. triggers: [],
  40. dsn: { host: 'localhost', user: 'root', password: '' },
  41. settings: {},
  42. connect: [Function: connect],
  43. add: [Function: add],
  44. remove: [Function: remove],
  45. stop: [Function: stop],
  46. reload: [Function: reload],
  47. includeSchema: [Function: includeSchema] }
  48.  
  49. var watcher =mysqlEventWatcher.add(
  50. 'your_database_name.your_table_name',
  51. function (oldRow, newRow, event) {}
  52. );
  53.  
  54. var ZongJi = require('zongji');
  55. var zongji = new ZongJi({
  56. host : 'localhost',
  57. user : 'user',
  58. password : 'password',
  59. debug: true
  60. });
  61.  
  62. zongji.on('binlog', function(evt) {
  63. evt.dump();
  64. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement