{"id":17132176,"url":"https://github.com/bitsofinfo/io-event-reactor-plugin-mysql","last_synced_at":"2025-03-24T05:18:44.507Z","repository":{"id":57275600,"uuid":"60559377","full_name":"bitsofinfo/io-event-reactor-plugin-mysql","owner":"bitsofinfo","description":"Mysql filesystem event reactor plugin for: io-event-reactor https://github.com/bitsofinfo/io-event-reactor","archived":false,"fork":false,"pushed_at":"2016-06-10T14:29:46.000Z","size":41,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-29T11:12:58.412Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitsofinfo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-06T20:40:32.000Z","updated_at":"2016-10-08T16:31:13.000Z","dependencies_parsed_at":"2022-09-15T19:12:42.400Z","dependency_job_id":null,"html_url":"https://github.com/bitsofinfo/io-event-reactor-plugin-mysql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitsofinfo%2Fio-event-reactor-plugin-mysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitsofinfo%2Fio-event-reactor-plugin-mysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitsofinfo%2Fio-event-reactor-plugin-mysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitsofinfo%2Fio-event-reactor-plugin-mysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitsofinfo","download_url":"https://codeload.github.com/bitsofinfo/io-event-reactor-plugin-mysql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245212311,"owners_count":20578443,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T19:26:16.740Z","updated_at":"2025-03-24T05:18:44.482Z","avatar_url":"https://github.com/bitsofinfo.png","language":"JavaScript","readme":"# io-event-reactor-plugin-mysql\n\nMysql filesystem event reactor plugin for: [io-event-reactor](https://github.com/bitsofinfo/io-event-reactor)\n\n[![NPM](https://nodei.co/npm/io-event-reactor-plugin-mysql.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/io-event-reactor-plugin-mysql/)\n\n## Usage\n\nTo configure this ReactorPlugin in your application that uses [io-event-reactor](https://github.com/bitsofinfo/io-event-reactor) do the following\n\n```\nnpm install io-event-reactor-plugin-mysql\n```\n\nThen in your [io-event-reactor](https://github.com/bitsofinfo/io-event-reactor) configuration object that you pass to the `IoReactorService`\nconstructor, you can specify this plugin in the `reactors` block as so:\n\n```\nvar ioReactorServiceConf = {\n\n  ...\n\n  ioReactors: [\n\n          {\n              id: \"reactor1\",\n\n              monitor: {\n                  ...\n              },\n\n              evaluators: [\n                  {\n                      evaluator: myEvaluatorFunction,\n                      reactors: ['mysql1,...'] // binds mysql to this evaluator\n                  }\n              ],\n\n              reactors: [\n\n                  // the \"id\" is what you use to bind this reactor\n                  // to an evaluator above\n                  { id: \"mysql1\",\n                    plugin: \"io-event-reactor-plugin-mysql\",\n\n                    config: {\n\n                          // a node-mysql connection pool configuration object:\n                          // see: https://github.com/felixge/node-mysql#pool-options\n                          //      https://github.com/felixge/node-mysql#connection-options,\n                          poolConfig : {\n                              host     : 'hostname',\n                              user     : 'username',\n                              password : 'pw',\n                              database : 'dbname',\n                              multipleStatements: true,\n                              ....\n                          },\n\n                          /**\n                          * 'sqlTemplates' - an array of mustache (https://github.com/janl/mustache.js) SQL template strings that will be executed\n                          *                  in order using node-mysql when this plugin's react() is invoked.\n                          *                  (all statements from here and sqlGenerator below exec in a single transaction)\n                          *\n                          *  Supported mustache template variables that will be made available to you: (a full IoEvent)\n                          *    - see https://github.com/bitsofinfo/io-event-reactor-plugin-support for IoEvent definition\n                          *    - ioEvent.uuid\n                          *    - ioEvent.eventType: one of: 'add', 'addDir', 'unlink', 'unlinkDir', 'change'\n                          *    - ioEvent.fullPath: string full path to file being reacted to (filename/dir inclusive)\n                          *    - ioEvent.parentPath: full path to the directory containing the item manipulated\n                          *    - ioEvent.parentName: parent directory name only\n                          *    - ioEvent.filename: filename/dirname only (no path information)\n                          *    - ioEvent.optionalFsStats: optional stats object -\u003e https://nodejs.org/docs/latest/api/fs.html#fs_class_fs_stats\n                          *    - ioEvent.optionalExtraInfo: optional object, see the MonitorPlugin you are using to see the spec and when/if its available\n                          */\n                          sqlTemplates: [\n                              'INSERT INTO io_event (eventType,fullPath,stats)      VALUES(\"{{{ioEvent.eventType}}}\",\"{{{ioEvent.fullPath}}}\",\"{{{ioEvent.optionalFsStats}}}\")'\n                          ],\n\n                          /**\n                          *  - 'sqlGenerator' - callback function(ioEvent) that must return an array[] of sql\n                          *                     statements literals that will be executed in order using\n                          *                     node-mysql when this plugin's react() is invoked.\n                          *                     (all statements from here and sqlTemplates above exec in a single transaction)\n                          */\n                          sqlGenerator: function(ioEvent) {\n                              return [('INSERT INTO io_event2 (eventType,fullPath,stats) VALUES(\"'+ioEvent.eventType+'\",\"'+ioEvent.fullPath+'\",\"'+(ioEvent.optionalFsStats ? ioEvent.optionalFsStats.size : '?') +'\")')];\n                          },\n                      }\n                  },\n\n                  ....\n              ]\n        },\n        ....\n    ]\n\n    ...\n};\n```\n\n### Security\n\nBe aware that this plugin takes raw input from events generated by a monitor plugin\nand allows you to use that data in custom SQL statements. This potentially could open you\nup to certain edge cases where SQL injection could occur. If you are concerned about this\nyou may only want to use the `sqlGenerator` option to pre-santize all arguments before you\ncreate SQL statements to be executed.\n\n### Unit tests\n\nTo run the unit tests go to the root of the project and run the following. Note the\n`username` below should have access to drop/create tables in the target `testDbName`\n\n```\nexport mysqlHost=[ip/host] mysqlUser=[username] mysqlPw=[pw] mysqlDb=[testDbName]; mocha test/all.js\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitsofinfo%2Fio-event-reactor-plugin-mysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitsofinfo%2Fio-event-reactor-plugin-mysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitsofinfo%2Fio-event-reactor-plugin-mysql/lists"}