Comparing version 0.4.2 to 0.4.3
40
index.js
@@ -28,2 +28,5 @@ var mysql = require('mysql'); | ||
this.useChecksum = false; | ||
// Include 'rotate' events to keep these properties updated | ||
this.binlogName = null; | ||
this.binlogNextPos = null; | ||
@@ -91,2 +94,7 @@ this._init(); | ||
if(('binlogName' in self.options) && ('binlogNextPos' in self.options)) { | ||
binlogOptions.filename = self.options.binlogName; | ||
binlogOptions.position = self.options.binlogNextPos | ||
} | ||
self.binlog = generateBinlog.call(self, binlogOptions); | ||
@@ -210,16 +218,24 @@ self.ready = true; | ||
if (event.getTypeName() === 'TableMap') { | ||
var tableMap = self.tableMap[event.tableId]; | ||
switch(event.getTypeName()) { | ||
case 'TableMap': | ||
var tableMap = self.tableMap[event.tableId]; | ||
if (!tableMap) { | ||
self.connection.pause(); | ||
self._fetchTableInfo(event, function() { | ||
// merge the column info with metadata | ||
event.updateColumnInfo(); | ||
self.emit('binlog', event); | ||
self.connection.resume(); | ||
}); | ||
return; | ||
} | ||
if (!tableMap) { | ||
self.connection.pause(); | ||
self._fetchTableInfo(event, function() { | ||
// merge the column info with metadata | ||
event.updateColumnInfo(); | ||
self.emit('binlog', event); | ||
self.connection.resume(); | ||
}); | ||
return; | ||
} | ||
break; | ||
case 'Rotate': | ||
if (self.binlogName !== event.binlogName) { | ||
self.binlogName = event.binlogName; | ||
} | ||
break; | ||
} | ||
self.binlogNextPos = event.nextPosition; | ||
self.emit('binlog', event); | ||
@@ -226,0 +242,0 @@ })); |
@@ -136,2 +136,4 @@ var util = require('util'); | ||
this._filtered = true; | ||
// Removed cached data so that row events do not emit either | ||
delete this.tableMap[this.tableId]; | ||
}else{ | ||
@@ -138,0 +140,0 @@ parser.parseUnsignedNumber(1); |
@@ -211,3 +211,2 @@ var iconv = require('iconv-lite'); | ||
var digitsPerInteger = 9; | ||
var bytesPerInteger = 4; | ||
var compressedBytes = [0, 1, 1, 2, 2, 3, 3, 4, 4, 4]; | ||
@@ -249,3 +248,3 @@ | ||
for(var i = 0; i < uncompIntegral; i++){ | ||
str += (buffer.readInt32BE(pos) ^ mask).toString(10); | ||
str += zeroPad((buffer.readInt32BE(pos) ^ mask).toString(10), 9); | ||
pos += 4; | ||
@@ -258,3 +257,3 @@ } | ||
for(var i = 0; i < uncompFractional; i++){ | ||
fractionDigits += (buffer.readInt32BE(pos) ^ mask).toString(10); | ||
fractionDigits += zeroPad((buffer.readInt32BE(pos) ^ mask).toString(10), 9); | ||
pos += 4; | ||
@@ -264,9 +263,8 @@ } | ||
var compFractionalSize = compressedBytes[compFractional]; | ||
if(compFractionalSize > 0){ | ||
fractionDigits += | ||
(readIntBE(buffer, pos, compFractionalSize) ^ mask).toString(10); | ||
if(compFractionalSize > 0) { | ||
fractionDigits += zeroPad((readIntBE(buffer, pos, compFractionalSize) ^ mask).toString(10), compFractional); | ||
} | ||
// Fractional digits may have leading zeros | ||
str += '.' + zeroPad(fractionDigits, scale); | ||
str += '.' + fractionDigits; | ||
@@ -273,0 +271,0 @@ return parseFloat(str); |
{ | ||
"name": "zongji", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"description": "A mysql binlog listener running on Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -77,2 +77,4 @@ # ZongJi [![Build Status](https://travis-ci.org/nevill/zongji.svg?branch=master)](https://travis-ci.org/nevill/zongji) | ||
`startAtEnd` | `boolean` | Pass `true` to only emit binlog events that occur after ZongJi's instantiation. Must be used in `start()` method for effect.<br>**Default:** `false` | ||
`binlogName` | `string` | Begin reading events from this binlog file. If specified together with `binlogNextPos`, will take precedence over `startAtEnd`. | ||
`binlogNextPos` | `integer` | Begin reading events from this position. Must be included with `binlogName`. | ||
`includeEvents` | `[string]` | Array of event names to include<br>**Example:** `['writerows', 'updaterows', 'deleterows']` | ||
@@ -92,3 +94,3 @@ `excludeEvents` | `[string]` | Array of event names to exclude<br>**Example:** `['rotate', 'tablemap']` | ||
`query` | [Insert/Update/Delete Query](http://dev.mysql.com/doc/internals/en/query-event.html) | ||
`rotate` | [New Binlog file](http://dev.mysql.com/doc/internals/en/rotate-event.html) (not required to be included to rotate to new files) | ||
`rotate` | [New Binlog file](http://dev.mysql.com/doc/internals/en/rotate-event.html) Not required to be included to rotate to new files, but it is required to be included in order to keep the `binlogName` and `binlogNextPos` properties updated with current values for [graceful restarting on errors](https://gist.github.com/numtel/5b37b2a7f47b380c1a099596c6f3db2f). | ||
`format` | [Format Description](http://dev.mysql.com/doc/internals/en/format-description-event.html) | ||
@@ -95,0 +97,0 @@ `xid` | [Transaction ID](http://dev.mysql.com/doc/internals/en/xid-event.html) |
75008
1801
138