Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mysql-live-select

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mysql-live-select

Live updating MySQL SELECT statements

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

mysql-live-select

NPM Package to provide events when a MySQL select statement result set changes.

Built using the zongji Binlog Tailer and node-mysql projects.

Installation

  • Add the package to your project:

    $ npm install mysql-live-select
    
  • Enable MySQL binlog in my.cnf, restart MySQL server after making the changes.

    # binlog config
    server-id        = 1
    binlog_format    = row
    log_bin          = /usr/local/var/log/mysql/mysql-bin.log
    binlog_do_db     = employees   # optional
    expire_logs_days = 10          # optional
    max_binlog_size  = 100M        # optional
    
  • Create an account with replication privileges:

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

LiveMysql Constructor

The LiveMysql constructor makes 3 connections to your MySQL database:

  • Connection for executing SELECT queries
  • Replication slave connection
  • information_schema connection for column information

One argument, an object defining the settings. In addition the node-mysql connection settings, the following settings are available:

SettingTypeDescription
serverIdintegerUnique number (1 - 232) to identify this replication slave instance. Must be specified if running more than one instance.
Default: 1
minIntervalintegerPass a number of milliseconds to use as the minimum between result set updates. Omit to refresh results on every update.
// Example:
var liveConnection = new LiveMysql(settings);
var table = 'players';
var id = 11;

liveConnection.select(function(esc, escId){
  return (
    'select * from ' + escId(table) +
    'where `id`=' + esc(id)
  );
}, [ {
  table: table,
  condition: function(row, newRow){ return row.id === id; }
} ]).on('update', function(data){
  console.log(data);
});

See example.js for full source...

LiveMysql.prototype.select(query, triggers)

ArgumentTypeDescription
querystring or functionSELECT SQL statement. See note below about passing function.
triggers[object]Array of objects defining which row changes to update result set

Returns LiveMysqlSelect object which inherits from EventEmitter, providing update and error events.

Function as query

A function may be passed as the query argument that accepts two arguments.

  • The first argument, esc is a function that escapes values in the query.
  • The second argument, escId is a function that escapes identifiers in the query.
Trigger options
NameTypeDescription
tablestringName of table (required)
databasestringName of database (optional)
Default: database setting specified on connection
conditionfunctionEvaluate row values (optional)
Condition Function

A condition function accepts one or two arguments:

Argument NameDescription
rowTable row data
newRowNew row data (only available on UPDATE queries)

Return true when the row data meets the condition to update the result set.

License

MIT

Keywords

FAQs

Package last updated on 02 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc