spencerlambert / mysql-events

A node meteor package that watches a MySQL database and runs callbacks on matched events.
Other
87 stars 74 forks source link

There isn't a difference between the update and delete #8

Closed happilymarrieddad closed 8 years ago

happilymarrieddad commented 8 years ago

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 } }
happilymarrieddad commented 8 years ago

Here is my connection code


      var MySQLEvents = require('mysql-events')
      var dsn = {
        host            : process.env.DB_HOST,
        user            : process.env.DB_USERNAME,
        password        : process.env.DB_PASSWORD
      }

      var mysqlEventWatcher1 = MySQLEvents(dsn)
      var watcher1 = mysqlEventWatcher1.add(
        process.env.DB_DATABASE,
        function(oldRow,newRow) {

          // Insert
          // if (oldRow === null) {
          //   console.log('')
          //   console.log('Insert')
          //   console.log(oldRow)
          //   console.log(newRow)
          //   console.log('')
          // }

          // // Deleted
          // if (newRow === null) {
          //   console.log('')
          //   console.log('Deleted')
          //   console.log(oldRow)
          //   console.log(newRow)
          //   console.log('')
          // }

          // // Updated
          // if (oldRow !== null && newRow !== null) {
          //   console.log('')
          //   console.log('Updated')
          //   console.log(oldRow)
          //   console.log(newRow)
          //   console.log('')
          // }

          console.log('')
          console.log('')
          console.log(oldRow)
          console.log(newRow)
          console.log('')
          console.log('')

        }
      )
sirhanshafahath commented 8 years ago

Can you please check your query again? It looks like an update calls o/p, changing the "visibility" from 1 => 0

spencerlambert commented 8 years ago

I don't think your database is doing an actual delete. If you look in index.js you'll find that newRow is explicitly set to null, when getting the delete message from the db.

            if (evt.getEventName() == 'deleterows') {
                newRow = null;
                oldRow = {
                  database: database,
                  table: table,
                  affectedColumns: columns,
                  changedColumns: changedColumns,
                  fields: row
                };
              }
happilymarrieddad commented 8 years ago

ah yes... lol thanks... it happened to be that table does a logical delete... sorry I didn't catch that. Thanks!