Registry / database / mysql-live-select

mysql-live-select

JSON →
library1.0.6jsnpmunverified

MySQL live select package that emits events when the result set of a SELECT statement changes. Built on top of zongji (binlog tailer) and node-mysql. Current stable version 1.0.6. Supports MySQL 5.1 to 5.7. Requires binlog enabled. Provides a LiveMysql constructor that makes three connections: for queries, replication, and information_schema. Releases are infrequent. Differentiator: enables real-time reactive UI updates from MySQL without polling.

npm install mysql-live-select
INSTALL
IMPORT
SIG · MYSQL-LIVE-SELECT
M
mysql-live-select
databasejavascriptv1.0.6
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.

default
import LiveMysql from 'mysql-live-select'
const { LiveMysql } = require('mysql-live-select')
Default export is the LiveMysql constructor. CJS require gives the constructor directly.
LiveMysql (type)
import type { LiveMysql } from 'mysql-live-select'
TypeScript users may need type import if using as a type.
default (CJS)
const LiveMysql = require('mysql-live-select')
const { LiveMysql } = require('mysql-live-select')
CommonJS require returns the constructor directly, not an object.

Creates a LiveMysql instance, waits for ready event, then registers a live SELECT query on the 'players' table with a condition to only fire when the row with id=11 changes.

import LiveMysql from 'mysql-live-select'; const settings = { host: 'localhost', user: 'user', password: process.env.MYSQL_PASSWORD ?? '', database: 'mydb', serverId: 100, minInterval: 1000 }; const liveConnection = new LiveMysql(settings); liveConnection.on('error', (err: Error) => { console.error('LiveMysql error:', err); }); liveConnection.on('ready', () => { const table = 'players'; const id = 11; liveConnection.select( (esc: Function, escId: Function) => { return 'select * from ' + escId(table) + ' where id = ' + esc(id); }, [{ table: table, condition: function(row: any, newRow: any) { return row.id === id || (newRow && newRow.id === id); } }], function(err: Error | null, rows: any[]) { if (err) { console.error('Query error:', err); } else { console.log('Result set changed:', rows); } } ); });
Debug
Known issues
gotchaRequires MySQL binlog to be enabled with row-based format. Without proper binlog configuration, the package will not work.
fix
Enable binlog in my.cnf: server-id=1, binlog_format=row, log_bin=/path/to/log, and grant REPLICATION SLAVE, REPLICATION CLIENT, SELECT privileges.
affects: >=1.0.0
gotchaThe callback parameter in the constructor is deprecated. Use the 'ready' event instead.
fix
Remove callback argument and use .on('ready', ...) to handle connection success.
affects: >=1.0.0
gotchaThe package makes three separate MySQL connections. Ensure your MySQL server allows multiple connections from the same user.
fix
Check max_connections and user connection limits. Use a dedicated user with sufficient connections.
affects: >=1.0.0
gotchaThe first argument to liveConnection.select() must be a function that returns a SQL string, not a raw string. Common mistake: passing a string directly.
fix
Wrap your query in a function with (esc, escId) parameters to properly escape values and identifiers.
affects: >=1.0.0
gotchaThe condition array elements must contain 'table' and 'condition' properties. Omitting 'table' will cause the regex to fail or match incorrectly.
fix
Ensure each condition object has a 'table' string and a 'condition' function.
affects: >=1.0.0
gotchaWhen checkConditionWhenQueued is not enabled (default), the condition function is not called again if the query is already queued. This can lead to missed updates.
fix
Set checkConditionWhenQueued: true if you need condition re-evaluation on every binlog event.
affects: >=1.0.0
Errors
Common errors & fixes
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'user'@'localhost' to database 'mydb'
User does not have sufficient privileges for replication or the database.
fix
Grant REPLICATION SLAVE, REPLICATION CLIENT, SELECT ON *.* TO 'user'@'localhost' and FLUSH PRIVILEGES.
Error: ER_BINLOG_ROW_MODE: Binary logging not enabled. Must be enabled with --log-bin and binlog_format=ROW.
MySQL binlog is not configured or not active.
fix
Enable binlog in my.cnf: server-id=1, binlog_format=row, log_bin=/path/to/log, then restart MySQL.
TypeError: liveConnection.select is not a function
Using require incorrectly: require('mysql-live-select') returns the constructor, not an object. Calling select on the constructor instead of an instance.
fix
Instantiate with new: const liveConnection = new LiveMysql(settings); then call liveConnection.select(...).
Error: Can't connect to MySQL server on 'localhost' (111)
MySQL server is not running or not accessible on the given host/port.
fix
Start MySQL server, check host and port settings, and ensure firewall allows connection.
Upgrade
Version history
1.0.6latest on npm
Audit
Dependencies
zongjirequiredreads MySQL binlog for change tracking
mysqlrequirednode-mysql driver for query execution and connections
Agent activity
4 hits · last 30 days
node
4
Resources
mysql-live-select — npm install mysql-live-select · libregistry