All Projects → nevill → Zongji

nevill / Zongji

Licence: other
A mysql binlog listener running on Node.js.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Zongji

Sqlc
Generate type-safe code from SQL
Stars: ✭ 4,564 (+1406.27%)
Mutual labels:  mysql
Sqlstring
Simple SQL escape and format for MySQL
Stars: ✭ 286 (-5.61%)
Mutual labels:  mysql
Neard
🎲 Portable WAMP software stack
Stars: ✭ 296 (-2.31%)
Mutual labels:  mysql
Arcemu
World Of Warcraft 3.3.5a server package
Stars: ✭ 281 (-7.26%)
Mutual labels:  mysql
Doctor
基于知识图谱的医学诊断系统。Medical Diagnosis System Based on Knowledge Map.
Stars: ✭ 286 (-5.61%)
Mutual labels:  mysql
Naivechat
🎭 本项目是作者小傅哥使用JavaFx、Netty4.x、SpringBoot、Mysql等技术栈和偏向于DDD领域驱动设计方式,搭建的仿桌面版微信实现通信核心功能。课程文章已发布到GitChat专栏,欢迎购买。如果本项目能为您提供帮助,请给予支持(关注、⭐️Star、分享)!
Stars: ✭ 290 (-4.29%)
Mutual labels:  mysql
Egg Mysql
MySQL plugin for egg
Stars: ✭ 276 (-8.91%)
Mutual labels:  mysql
Scalikejdbc Async
ScalikeJDBC Extension: Non-blocking APIs in the JDBC way
Stars: ✭ 300 (-0.99%)
Mutual labels:  mysql
Mysql
A pure node.js JavaScript Client implementing the MySQL protocol.
Stars: ✭ 16,878 (+5470.3%)
Mutual labels:  mysql
Crud
Relational database library for SQL databases & Go.
Stars: ✭ 296 (-2.31%)
Mutual labels:  mysql
Cool Admin Midway
cool-admin(midway版)一个很酷的后台权限管理框架,模块化、插件化、CRUD极速开发,永久开源免费,基于midway.js 2.0、typeorm、mysql、jwt、element-ui等构建
Stars: ✭ 204 (-32.67%)
Mutual labels:  mysql
Sql Parser
A validating SQL lexer and parser with a focus on MySQL dialect.
Stars: ✭ 284 (-6.27%)
Mutual labels:  mysql
Requery
requery - modern SQL based query & persistence for Java / Kotlin / Android
Stars: ✭ 3,071 (+913.53%)
Mutual labels:  mysql
Spring Boot Mysql Rest Api Tutorial
Building a Restful CRUD API using Spring Boot, Mysql, JPA and Hibernate
Stars: ✭ 279 (-7.92%)
Mutual labels:  mysql
Mysqlconvertertool
A MySQL Converter Tool
Stars: ✭ 299 (-1.32%)
Mutual labels:  mysql
Phpminiadmin
extremely lightweight alternative to heavy phpMyAdmin for quick and easy access MySQL databases
Stars: ✭ 278 (-8.25%)
Mutual labels:  mysql
Mysql Tutorial
MySQL入门教程(MySQL tutorial book)
Stars: ✭ 3,247 (+971.62%)
Mutual labels:  mysql
Tormysql
The highest performance asynchronous MySQL driver by PyMySQL
Stars: ✭ 302 (-0.33%)
Mutual labels:  mysql
Many People Blog
🎈基于vue+node+mysql的多人博客,带后台管理系统。支持:登陆/注册,留言,评论/回复,点赞,记录浏览数量,带有相册功能,内容丰富,当然也可以发表文章。欢迎使用!
Stars: ✭ 300 (-0.99%)
Mutual labels:  mysql
Node Orm2
Object Relational Mapping
Stars: ✭ 3,063 (+910.89%)
Mutual labels:  mysql

ZongJi Build Status

A MySQL binlog listener running on Node.js.

ZongJi (踪迹) is pronounced as zōng jì in Chinese.

This package is a pure JS implementation based on mysql. It has been tested to work in MySQL 5.5, 5.6, and 5.7.

Latest Release

The latest release is v0.5.0, only supports Node.js from v8.

v0.4.7 is the last release which supports Node.js v4.x.

Quick Start

let zongji = new ZongJi({ /* ... MySQL Connection Settings ... */ });

// Each change to the replication log results in an event
zongji.on('binlog', function(evt) {
  evt.dump();
});

// Binlog must be started, optionally pass in filters
zongji.start({
  includeEvents: ['tablemap', 'writerows', 'updaterows', 'deleterows']
});

For a complete implementation see example.js...

Installation

  • Requires Node.js v8+

    $ npm install zongji
    
  • Enable MySQL binlog in my.cnf, restart MySQL server after making the changes.

    From MySQL 5.6, binlog checksum is enabled by default. Zongji can work with it, but it doesn't really verify it.

    # Must be unique integer from 1-2^32
    server-id        = 1
    # Row format required for ZongJi
    binlog_format    = row
    # Directory must exist. This path works for Linux. Other OS may require
    #   different path.
    log_bin          = /var/log/mysql/mysql-bin.log
    
    binlog_do_db     = employees   # Optional, limit which databases to log
    expire_logs_days = 10          # Optional, purge old logs
    max_binlog_size  = 100M        # Optional, limit log size
    
  • Create an account with replication privileges, e.g. given privileges to account zongji (or any account that you use to read binary logs)

    GRANT REPLICATION SLAVE, REPLICATION CLIENT, SELECT ON *.* TO 'zongji'@'localhost'
    

ZongJi Class

The ZongJi constructor accepts one argument of either:

  • An object containing MySQL connection details in the same format as used by package mysql
  • Or, a mysql Connection or Pool object that will be used for querying column information.

If a Connection or Pool object is passed to the constructor, it will not be destroyed/ended by Zongji's stop() method.

If there is a dateStrings mysql configuration option in the connection details or connection, ZongJi will follow it.

Each instance includes the following methods:

Method Name Arguments Description
start options Start receiving replication events, see options listed below
stop None Disconnect from MySQL server, stop receiving events
on eventName, handler Add a listener to the binlog or error event. Each handler function accepts one argument.

Some events can be emitted in different phases:

Event Name Description
ready This event is occurred right after ZongJi successfully established a connection, setup slave status, and set binlog position.
binlog Once a binlog is received and passes the filter, it will bubble up with this event.
error Every error will be caught by this event.
stopped Emitted when ZongJi connection is stopped (ZongJi#stop is called).

Options available:

Option Name Type Description
serverId integer Unique number (1 - 232) 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.
Default: 1
startAtEnd boolean Pass true to only emit binlog events that occur after ZongJi's instantiation. Must be used in start() method for effect.
Default: false
filename string Begin reading events from this binlog file. If specified together with position, will take precedence over startAtEnd.
position integer Begin reading events from this position. Must be included with filename.
includeEvents [string] Array of event names to include
Example: ['writerows', 'updaterows', 'deleterows']
excludeEvents [string] Array of event names to exclude
Example: ['rotate', 'tablemap']
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).
Example: { 'my_database': ['allow_table', 'another_table'], 'another_db': true }
excludeSchema object Object describing which databases and tables to exclude (Same format as includeSchema)
Example: { 'other_db': ['disallowed_table'], 'ex_db': true }
  • By default, all events and schema are emitted.
  • excludeSchema and excludeEvents take precedence over includeSchema and includeEvents, respectively.

Supported Binlog Events:

Event name Description
unknown Catch any other events
query Insert/Update/Delete Query
intvar Autoincrement and LAST_INSERT_ID
rotate New Binlog file 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.
format Format Description
xid Transaction ID
tablemap Before any row event (must be included for any other row events)
writerows Rows inserted, row data array available as rows property on event object
updaterows Rows changed, row data array available as rows property on event object
deleterows Rows deleted, row data array available as rows property on event object

Event Methods

Neither method requires any arguments.

Name Description
dump Log a description of the event to the console
getEventName Return the name of the event

Important Notes

  • 🌟 All types allowed by mysql are supported by this package.
  • 🙊 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.
  • 👉 TRUNCATE statement does not cause corresponding DeleteRows event. Use unqualified DELETE FROM for same effect.
  • 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.

Run Tests

  • install Docker
  • run docker-compose up and then ./docker-test.sh

Reference

I learnt many things from following resources while making ZongJi.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].