npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

io-event-reactor-plugin-mysql

v1.0.0-beta.6

Published

Mysql event reactor plugin for the io-event-reactor module

Downloads

17

Readme

io-event-reactor-plugin-mysql

Mysql filesystem event reactor plugin for: io-event-reactor

NPM

Usage

To configure this ReactorPlugin in your application that uses io-event-reactor do the following

npm install io-event-reactor-plugin-mysql

Then in your io-event-reactor configuration object that you pass to the IoReactorService constructor, you can specify this plugin in the reactors block as so:

var ioReactorServiceConf = {

  ...

  ioReactors: [

          {
              id: "reactor1",

              monitor: {
                  ...
              },

              evaluators: [
                  {
                      evaluator: myEvaluatorFunction,
                      reactors: ['mysql1,...'] // binds mysql to this evaluator
                  }
              ],

              reactors: [

                  // the "id" is what you use to bind this reactor
                  // to an evaluator above
                  { id: "mysql1",
                    plugin: "io-event-reactor-plugin-mysql",

                    config: {

                          // a node-mysql connection pool configuration object:
                          // see: https://github.com/felixge/node-mysql#pool-options
                          //      https://github.com/felixge/node-mysql#connection-options,
                          poolConfig : {
                              host     : 'hostname',
                              user     : 'username',
                              password : 'pw',
                              database : 'dbname',
                              multipleStatements: true,
                              ....
                          },

                          /**
                          * 'sqlTemplates' - an array of mustache (https://github.com/janl/mustache.js) SQL template strings that will be executed
                          *                  in order using node-mysql when this plugin's react() is invoked.
                          *                  (all statements from here and sqlGenerator below exec in a single transaction)
                          *
                          *  Supported mustache template variables that will be made available to you: (a full IoEvent)
                          *    - see https://github.com/bitsofinfo/io-event-reactor-plugin-support for IoEvent definition
                          *    - ioEvent.uuid
                          *    - ioEvent.eventType: one of: 'add', 'addDir', 'unlink', 'unlinkDir', 'change'
                          *    - ioEvent.fullPath: string full path to file being reacted to (filename/dir inclusive)
                          *    - ioEvent.parentPath: full path to the directory containing the item manipulated
                          *    - ioEvent.parentName: parent directory name only
                          *    - ioEvent.filename: filename/dirname only (no path information)
                          *    - ioEvent.optionalFsStats: optional stats object -> https://nodejs.org/docs/latest/api/fs.html#fs_class_fs_stats
                          *    - ioEvent.optionalExtraInfo: optional object, see the MonitorPlugin you are using to see the spec and when/if its available
                          */
                          sqlTemplates: [
                              'INSERT INTO io_event (eventType,fullPath,stats)      VALUES("{{{ioEvent.eventType}}}","{{{ioEvent.fullPath}}}","{{{ioEvent.optionalFsStats}}}")'
                          ],

                          /**
                          *  - 'sqlGenerator' - callback function(ioEvent) that must return an array[] of sql
                          *                     statements literals that will be executed in order using
                          *                     node-mysql when this plugin's react() is invoked.
                          *                     (all statements from here and sqlTemplates above exec in a single transaction)
                          */
                          sqlGenerator: function(ioEvent) {
                              return [('INSERT INTO io_event2 (eventType,fullPath,stats) VALUES("'+ioEvent.eventType+'","'+ioEvent.fullPath+'","'+(ioEvent.optionalFsStats ? ioEvent.optionalFsStats.size : '?') +'")')];
                          },
                      }
                  },

                  ....
              ]
        },
        ....
    ]

    ...
};

Security

Be aware that this plugin takes raw input from events generated by a monitor plugin and allows you to use that data in custom SQL statements. This potentially could open you up to certain edge cases where SQL injection could occur. If you are concerned about this you may only want to use the sqlGenerator option to pre-santize all arguments before you create SQL statements to be executed.

Unit tests

To run the unit tests go to the root of the project and run the following. Note the username below should have access to drop/create tables in the target testDbName

export mysqlHost=[ip/host] mysqlUser=[username] mysqlPw=[pw] mysqlDb=[testDbName]; mocha test/all.js