Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
BinlogTriggers
✓ import { BinlogTriggers } from 'binlog-triggers-mysql'
✗ import BinlogTriggers from 'binlog-triggers-mysql'
This is a named export, not a default export.
DbConfig
✓ import { DbConfig } from 'binlog-triggers-mysql'
TypeScript interface for database configuration.
trigger
✓ import { trigger } from 'binlog-triggers-mysql'
✗ const trigger = require('binlog-triggers-mysql').trigger
Available as named export. The trigger function is used for setting up handlers.
Demonstrates connecting to a MySQL database, setting up binlog event handlers for insert/update/delete on the 'test' table, and starting the binlog listener.
import { BinlogTriggers, DbConfig } from 'binlog-triggers-mysql';
const binlogTriggers = new BinlogTriggers();
let countRows = 0;
binlogTriggers.table('test', {
insert: (rows) => {
console.log('Got new rows', rows);
countRows++;
},
update: (rows) => {
console.log('Updated rows', rows);
},
delete: (rows) => {
console.log('Deleted rows', rows);
}
});
const dbConfig: DbConfig = {
database: 'binlog_demo',
host: process.env.DB_HOST ?? 'localhost',
password: process.env.DB_PASSWORD ?? 'test',
user: 'test',
port: 3306
};
binlogTriggers.start(dbConfig);
// After some time, stop listening
setTimeout(() => {
binlogTriggers.stop();
console.log('Total rows inserted:', countRows);
}, 10000);
Errors
Common errors & fixes
Cannot find module 'zongji'
Missing dependency zongji, which is required by binlog-triggers-mysql.
fixRun npm install zongji or ensure it is in package.json dependencies.
TypeError: binlogTriggers.start is not a function
Using older API where start() was named differently or arguments mismatch.
fixEnsure you are using version >=1.0.0 and call start() with a DbConfig object.
Error: ER_BINLOG_ROW_LOGGING_REQUIRED: Binary logging must be enabled with row-based format.
MySQL binary logging is not configured correctly.
fixEnable binary logging and set binlog_format=ROW in MySQL configuration.
Audit
Dependencies
zongjirequiredUsed internally to parse MySQL binlog messages.