{"_id":"@amokrushin/zongji","_rev":"2-6e39c03e67f4a0be01ef36acde2c923c","name":"@amokrushin/zongji","dist-tags":{"latest":"0.5.1-patch.1"},"versions":{"0.4.8":{"name":"@amokrushin/zongji","version":"0.4.8","description":"A mysql binlog listener running on Node.js","main":"index.js","directories":{"lib":"lib","test":"test"},"scripts":{"test":"nodeunit --reporter=minimal test","lint":"eslint ."},"repository":{"type":"git","url":"git+https://github.com/amokrushin/zongji.git"},"keywords":["mysql","binlog"],"author":{"name":"Nevill","email":"nevill.dutt@gmail.com"},"contributors":[{"name":"numtel","email":"ben@latenightsketches.com","url":"https://github.com/numtel"},{"name":"rfanth","email":"rfa@rfanth.com","url":"https://github.com/rfanth"}],"license":"MIT","bugs":{"url":"https://github.com/amokrushin/zongji/issues"},"homepage":"https://github.com/amokrushin/zongji","devDependencies":{"eslint":"2.13.1","nodeunit":"~0.9.1"},"dependencies":{"iconv-lite":"^0.4.13","mysql":"2.16.0"},"publishConfig":{"access":"public"},"gitHead":"0217dd477221c457f0b4f01e471bdbc53d0e8eee","_id":"@amokrushin/zongji@0.4.8","_nodeVersion":"10.4.1","_npmVersion":"6.9.0","dist":{"integrity":"sha512-AOJrE99FB4Zsjvnjrd5smrhmU2tjDZ4h1JCn1gzaDedn6SymuBpDb6ZHdShYbvNI5pyWVb1RaUtv4z6q1rq8MA==","shasum":"3b1cb176813e05bec1397d38c8b1ee519d5e68ce","tarball":"https://registry.npmjs.org/@amokrushin/zongji/-/zongji-0.4.8.tgz","fileCount":21,"unpackedSize":84616,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJckWKJCRA9TVsSAnZWagAArcEQAJb/G5jrHyU4x03TLsMt\n+qGJ/e8A9k0JpXQLjK9mRzELnK1A+HUZiUawQ3ec7BhJO1p2LCYD8nXOuam1\nPwAHQhTwZvawZjzqy5N52h4Q+TStbri4tFYvhUiHrpaAwm7Ief9f9fgg/0RN\ntbXPo9D+IUqgnujk41uL5S4S/IHLVFq+ASh2hYbH9YwEfo8sAxDp4Dsx7Xb4\nOOFOVLSpxu9j/etYrvFQ0GEQEqRZCKwfmrtFnz0m3mmmd2I7BAgh1DW6vy8P\n7BZMHJNCaZJeUyPrXIN42zbiiri/cfVE0B7Aap95bjSCWRqgp0mK4zCpcmHm\n4qTB6e2AY0qtnvqwl13fbvVIwoL9en+QVFbYhcjsU2+/9qMeEmqbYuO3F5qU\nTSRSN0c32O6J2ggMZLdM/UayeP3YEv2dJpo3Su56u5R8Z3poddNGN9DSbEq3\nteBtNVFR8EUK/5uOiJZB0QLFw2cWnfTZdGbK4xIQBHLxgCN7b/EfGkGjdY9p\nlZ+HptjgiXwnS6xQEsLmL/aAyhO2I3BCg6W2C7OXvTf7EDzCsTVaFbspSIin\nJfjGnUMMZV2nKJm0C6Z80CX7FcAGNswNqa6hpGrG6RqaRXJhlunR2uxROp++\nnbCM65lA/QgZ5Z2RopzvpWLTCZwGAzRWiWgoAlg7pIuDJUDmtM47aUoGvzXY\nZZl5\r\n=rdgE\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAGJJukRlqVlqtJRDS3Lx8b6hD7mj5Z0Dne8IFDYrQU0AiEAx9zNo7RiH8HxF9fnDiufs1QjmJElZ2xOsxkT1jP1Gj8="}]},"maintainers":[{"name":"amokrushin","email":"anton@mokr.org"}],"_npmUser":{"name":"amokrushin","email":"anton@mokr.org"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/zongji_0.4.8_1553031817292_0.2152915218585858"},"_hasShrinkwrap":false},"0.5.1-patch.1":{"name":"@amokrushin/zongji","version":"0.5.1-patch.1","description":"A mysql binlog listener running on Node.js","main":"index.js","directories":{"test":"test"},"scripts":{"test":"tap --bail --no-coverage --jobs=1 test/*.js","lint":"eslint ."},"repository":{"type":"git","url":"git+https://github.com/amokrushin/zongji.git"},"keywords":["mysql","binlog"],"author":{"name":"Nevill","email":"nevill.dutt@gmail.com"},"contributors":[{"name":"numtel","email":"ben@latenightsketches.com","url":"https://github.com/numtel"},{"name":"rfanth","email":"rfa@rfanth.com","url":"https://github.com/rfanth"}],"license":"MIT","bugs":{"url":"https://github.com/amokrushin/zongji/issues"},"homepage":"https://github.com/amokrushin/zongji","engines":{"node":">= 8.0"},"devDependencies":{"eslint":"6.5.1","tap":"14.8.2"},"dependencies":{"big-integer":"1.6.47","iconv-lite":"0.4.24","mysql":"2.17.1"},"publishConfig":{"access":"public"},"gitHead":"785d01da322e0787756b768b0e893741feb85e4c","_id":"@amokrushin/zongji@0.5.1-patch.1","_nodeVersion":"12.14.1","_npmVersion":"6.13.4","dist":{"integrity":"sha512-WKbaDAG4XompW28vlLMW0lr6rzLFyZVdtkeZo0XyG5H6DlV40DJQJThquQgcDSuKT9FV0fmsjywdoiyLk+tDXA==","shasum":"3d16a80c1a6a3355c346311e64c52a30ef96fe78","tarball":"https://registry.npmjs.org/@amokrushin/zongji/-/zongji-0.5.1-patch.1.tgz","fileCount":27,"unpackedSize":90927,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeZX7gCRA9TVsSAnZWagAAtLAP/0OTAAP3BAmGLVhUWZTf\ndVvVXJB4CtPEwf9v2tHbpCBn6MBPc/GucI0pvKQKyq+a5fFGvdlWDuKxHT7b\n/9svn74SlpaJC+sPcyFKdzOG6/WeEk5RomaLbt8iKffbslE0zPSPbEAFHeVF\n3jV4TWA11o/tZ87RaXVYHXvLw7FXdoTi8EbrGLLtPLIb7scutpmD5ujut5tI\nZh1YSvT65UKE6VcBejbk+qVGByi0WFMbKXxCbfW31+xpnYdxtSJ7v5k5fG4v\neqa+efSL0stSMAUXxE91y+bhkFSU0YRMnI3QGb3u9ZX6Jzc2Q1oqhYP2isOi\nj80aII1FjM+WhG9SDw7NLD5I6AzTlr5bbP0RO2ii8gXg5dxzKvfe5vMZ49LO\n1jDHMOGoKWiHSRALFVaFbpvEhouNvD1vjTf0GgmLY2p4yTMJE8tT09PzmQ66\nk3HGILXqlkhaAQkq+3A8Pr8WMlacJD6QvCYCnDD84mGkLx9XtEbwfVryEwE2\nphsoWqbhktmN+c1LnG/luDacIa0EcI2WOl7UOmRKZ8pYqa+97Jyv4dvurU8q\nljJC7RDu++G0B6zoUYQeW0+9nM7S5QY44zy08uFCP7QDfYZDnUWElMrdyp+T\nGvBactzUuJhdxEOdHotk309plwXuAmODHRk7b7wEw+zsg8Ge5tj3YBpjyJMD\nfigt\r\n=K6Ut\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDozqFCAdnGSrSWdUiFUtjBp40S40naZ4q0Xhlvm7UEfQIhANi0dLkPUgiQYZofUlvz0PnTTgp0JmUNZXXD9NIrVa6u"}]},"maintainers":[{"name":"amokrushin","email":"anton@mokr.org"}],"_npmUser":{"name":"amokrushin","email":"anton@mokr.org"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/zongji_0.5.1-patch.1_1583709920183_0.4365097902447794"},"_hasShrinkwrap":false}},"time":{"created":"2019-03-19T21:43:37.110Z","0.4.8":"2019-03-19T21:43:37.435Z","modified":"2022-04-04T13:50:34.989Z","0.5.1-patch.1":"2020-03-08T23:25:20.269Z"},"maintainers":[{"name":"amokrushin","email":"anton@mokr.org"}],"description":"A mysql binlog listener running on Node.js","homepage":"https://github.com/amokrushin/zongji","keywords":["mysql","binlog"],"repository":{"type":"git","url":"git+https://github.com/amokrushin/zongji.git"},"contributors":[{"name":"numtel","email":"ben@latenightsketches.com","url":"https://github.com/numtel"},{"name":"rfanth","email":"rfa@rfanth.com","url":"https://github.com/rfanth"}],"author":{"name":"Nevill","email":"nevill.dutt@gmail.com"},"bugs":{"url":"https://github.com/amokrushin/zongji/issues"},"license":"MIT","readme":"# ZongJi [![Build Status](https://travis-ci.org/nevill/zongji.svg?branch=master)](https://travis-ci.org/nevill/zongji)\nA MySQL binlog listener running on Node.js.\n\nZongJi (踪迹) is pronounced as `zōng jì` in Chinese.\n\nThis package is a pure JS implementation based on [`mysql`](https://github.com/mysqljs/mysql). It has been tested to work in MySQL 5.5, 5.6, and 5.7.\n\n# Latest Release\n\nThe latest release is v0.5.0, only supports Node.js from v8.\n\nv0.4.7 is the last release which supports Node.js v4.x.\n\n## Quick Start\n\n```javascript\nlet zongji = new ZongJi({ /* ... MySQL Connection Settings ... */ });\n\n// Each change to the replication log results in an event\nzongji.on('binlog', function(evt) {\n  evt.dump();\n});\n\n// Binlog must be started, optionally pass in filters\nzongji.start({\n  includeEvents: ['tablemap', 'writerows', 'updaterows', 'deleterows']\n});\n```\n\nFor a complete implementation see [`example.js`](example.js)...\n\n## Installation\n\n* Requires Node.js v8+\n\n  ```bash\n  $ npm install zongji\n  ```\n\n* Enable MySQL binlog in `my.cnf`, restart MySQL server after making the changes.\n  > From [MySQL 5.6](https://dev.mysql.com/doc/refman/5.6/en/replication-options-binary-log.html), binlog checksum is enabled by default. Zongji can work with it, but it doesn't really verify it.\n\n  ```\n  # Must be unique integer from 1-2^32\n  server-id        = 1\n  # Row format required for ZongJi\n  binlog_format    = row\n  # Directory must exist. This path works for Linux. Other OS may require\n  #   different path.\n  log_bin          = /var/log/mysql/mysql-bin.log\n\n  binlog_do_db     = employees   # Optional, limit which databases to log\n  expire_logs_days = 10          # Optional, purge old logs\n  max_binlog_size  = 100M        # Optional, limit log size\n  ```\n* Create an account with replication privileges, e.g. given privileges to account `zongji` (or any account that you use to read binary logs)\n\n  ```sql\n  GRANT REPLICATION SLAVE, REPLICATION CLIENT, SELECT ON *.* TO 'zongji'@'localhost'\n  ```\n\n## ZongJi Class\n\nThe `ZongJi` constructor accepts one argument of either:\n\n* An object containing MySQL connection details in the same format as used by [package mysql](https://npm.im/mysql)\n* Or, a [mysql](https://npm.im/mysql) `Connection` or `Pool` object that will be used for querying column information.\n\nIf a `Connection` or `Pool` object is passed to the constructor, it will not be destroyed/ended by Zongji's `stop()` method.\n\nIf there is a `dateStrings` `mysql` configuration option in the connection details or connection, `ZongJi` will follow it.\n\nEach instance includes the following methods:\n\nMethod Name | Arguments | Description\n------------|-----------|------------------------\n`start`     | `options` | Start receiving replication events, see options listed below\n`stop`      | *None*    | Disconnect from MySQL server, stop receiving events\n`on`        | `eventName`, `handler` | Add a listener to the `binlog` or `error` event. Each handler function accepts one argument.\n\nSome events can be emitted in different phases:\n\nEvent Name | Description\n-----------|------------------------\n`ready`    | This event is occurred right after ZongJi successfully established a connection, setup slave status, and set binlog position.\n`binlog`   | Once a binlog is received and passes the filter, it will bubble up with this event.\n`error`    | Every error will be caught by this event.\n`stopped`  | Emitted when ZongJi connection is stopped (ZongJi#stop is called).\n\n**Options available:**\n\nOption Name | Type | Description\n------------|------|-------------------------------\n`serverId`  | `integer` | [Unique number (1 - 2<sup>32</sup>)](http://dev.mysql.com/doc/refman/5.0/en/replication-options.html#option_mysqld_server-id) to identify this replication slave instance. Must be specified if running more than one instance of ZongJi. Must be used in `start()` method for effect.<br>**Default:** `1`\n`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`\n`filename` | `string` | Begin reading events from this binlog file. If specified together with `position`, will take precedence over `startAtEnd`.\n`position` | `integer` | Begin reading events from this position. Must be included with `filename`.\n`includeEvents` | `[string]` | Array of event names to include<br>**Example:** `['writerows', 'updaterows', 'deleterows']`\n`excludeEvents` | `[string]` | Array of event names to exclude<br>**Example:** `['rotate', 'tablemap']`\n`includeSchema` | `object` | Object describing which databases and tables to include (Only for row events). Use database names as the key and pass an array of table names or `true` (for the entire database).<br>**Example:** ```{ 'my_database': ['allow_table', 'another_table'], 'another_db': true }```\n`excludeSchema` | `object` | Object describing which databases and tables to exclude (Same format as `includeSchema`)<br>**Example:** ```{ 'other_db': ['disallowed_table'], 'ex_db': true }```\n\n* By default, all events and schema are emitted.\n* `excludeSchema` and `excludeEvents` take precedence over `includeSchema` and `includeEvents`, respectively.\n\n**Supported Binlog Events:**\n\nEvent name  | Description\n------------|---------------\n`unknown`   | Catch any other events\n`query`     | [Insert/Update/Delete Query](http://dev.mysql.com/doc/internals/en/query-event.html)\n`intvar`    | [Autoincrement and LAST_INSERT_ID](https://dev.mysql.com/doc/internals/en/intvar-event.html)\n`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 `filename` and `position` properties updated with current values for [graceful restarting on errors](https://gist.github.com/numtel/5b37b2a7f47b380c1a099596c6f3db2f).\n`format`    | [Format Description](http://dev.mysql.com/doc/internals/en/format-description-event.html)\n`xid`       | [Transaction ID](http://dev.mysql.com/doc/internals/en/xid-event.html)\n`tablemap`  | Before any row event (must be included for any other row events)\n`writerows` | Rows inserted, row data array available as `rows` property on event object\n`updaterows` | Rows changed, row data array available as `rows` property on event object\n`deleterows` | Rows deleted, row data array available as `rows` property on event object\n\n**Event Methods**\n\nNeither method requires any arguments.\n\nName   | Description\n-------|---------------------------\n`dump` | Log a description of the event to the console\n`getEventName` | Return the name of the event\n\n## Important Notes\n\n* :star2: [All types allowed by `mysql`](https://github.com/mysqljs/mysql#type-casting) are supported by this package.\n* :speak_no_evil: 64-bit integer is supported via package big-integer(see #108). If an integer is within the safe range of JS number (-2^53, 2^53), a Number object will returned, otherwise, will return as String.\n* :point_right: `TRUNCATE` statement does not cause corresponding `DeleteRows` event. Use unqualified `DELETE FROM` for same effect.\n* When using fractional seconds with `DATETIME` and `TIMESTAMP` data types in MySQL > 5.6.4, only millisecond precision is available due to the limit of Javascript's `Date` object.\n\n## Run Tests\n\n* install [Docker](https://www.docker.com/community-edition#download)\n* run `docker-compose up` and then `./docker-test.sh`\n\n## Reference\n\nI learnt many things from following resources while making ZongJi.\n\n* https://github.com/mysqljs/mysql\n* https://github.com/felixge/faster-than-c/\n* http://intuitive-search.blogspot.co.uk/2011/07/binary-log-api-and-replication-listener.html\n* https://github.com/Sannis/node-mysql-libmysqlclient\n* https://kkaefer.com/node-cpp-modules/\n* http://dev.mysql.com/doc/internals/en/replication-protocol.html\n* http://www.cs.wichita.edu/~chang/lecture/cs742/program/how-mysql-c-api.html\n* https://github.com/jeremycole/mysql_binlog (Ruby implemenation of MySQL binlog parser)\n* http://dev.mysql.com/doc/internals/en/date-and-time-data-type-representation.html\n\n## License\nMIT\n","readmeFilename":"README.md"}