Registry / database / binlog-triggers-mysql

binlog-triggers-mysql

JSON →
library1.1.4jsnpmunverified

API for listening to MySQL binlog events, filtered by table and operation type. Current stable version 1.1.4. Based on the zongji MySQL binlog parsing library. Provides automatic MySQL reconnection on network issues or server restarts. Ships TypeScript type definitions.

npm install binlog-triggers-mysql
INSTALL
IMPORT
SIG · BINLOG-TRIGGERS-MY
B
binlog-triggers-mysql
databasejavascriptv1.1.4
harness data pending
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);
Debug
Known issues
gotchaRequires MySQL binary logging to be enabled (binlog_format = ROW). If not enabled, library will fail silently or throw an error.
fix
Set MySQL server variable binlog_format = ROW and ensure binlog is enabled.
affects: >=1.0.0
gotchaEvent handlers must be registered before calling start(). If handlers are added after start, they may not be applied.
fix
Register all table handlers before calling start().
affects: >=1.0.0
gotchaThe library does not handle connection closed errors automatically in all cases; reconnection may not work for certain error types.
fix
Implement custom retry logic or increase connection timeout.
affects: >=1.0.0
breakingVersion 1.0.0 introduced a change in API: start() now requires a DbConfig object instead of individual parameters.
fix
Update calls to start() to pass a single DbConfig object.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'zongji'
Missing dependency zongji, which is required by binlog-triggers-mysql.
fix
Run 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.
fix
Ensure 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.
fix
Enable binary logging and set binlog_format=ROW in MySQL configuration.
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies
zongjirequiredUsed internally to parse MySQL binlog messages.
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
2
Resources
binlog-triggers-mysql — npm install binlog-triggers-mysql · libregistry