{"id":18304558,"url":"https://github.com/numtel/sails-mysql-live-select","last_synced_at":"2025-04-12T15:20:29.021Z","repository":{"id":143907385,"uuid":"44412194","full_name":"numtel/sails-mysql-live-select","owner":"numtel","description":"SailsJS Connection adapter for live real time MySQL result set updates","archived":false,"fork":false,"pushed_at":"2017-01-04T14:26:20.000Z","size":260,"stargazers_count":3,"open_issues_count":5,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-26T09:51:12.527Z","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/numtel.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-16T21:46:29.000Z","updated_at":"2018-11-22T08:47:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"e5d8c36a-c61b-4381-b695-72c8449c88da","html_url":"https://github.com/numtel/sails-mysql-live-select","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/numtel%2Fsails-mysql-live-select","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fsails-mysql-live-select/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fsails-mysql-live-select/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fsails-mysql-live-select/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/numtel","download_url":"https://codeload.github.com/numtel/sails-mysql-live-select/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248586218,"owners_count":21128998,"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-11-05T15:29:19.898Z","updated_at":"2025-04-12T15:20:28.991Z","avatar_url":"https://github.com/numtel.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sails-mysql-live-select [![Build Status](https://travis-ci.org/numtel/sails-mysql-live-select.svg?branch=master)](https://travis-ci.org/numtel/sails-mysql-live-select)\n\nA [Sails](http://sailsjs.org) connection adapter to use [the `mysql-live-select` NPM Package](https://github.com/numtel/mysql-live-select) in order to provide live (real time) result sets for models.\n\n## Example\n\nSee the [chat room example application](https://github.com/numtel/sails-mysql-live-select-chat-example) for a full working demonstration of this package.\n\n## Installation\n\nTo be used alongside the [`sails-mysql` connection adapter](https://github.com/balderdashy/sails-mysql).\n\n### MySQL server configuration\n\nA MySQL server properly configured to output the binary log in `ROW` mode is required to use this adapter:\n\n* Enable MySQL binlog in `my.cnf`, restart MySQL server after making the changes.\n\n  ```\n  # binlog config\n  server-id        = 1\n  binlog_format    = row\n  log_bin          = /var/log/mysql/mysql-bin.log\n  binlog_do_db     = employees   # optional\n  expire_logs_days = 10          # optional\n  max_binlog_size  = 100M        # optional\n  ```\n* Create an account with replication privileges:\n\n  ```sql\n  GRANT REPLICATION SLAVE, REPLICATION CLIENT, SELECT ON *.* TO 'user'@'localhost'\n  ```\n\n### Package installation\n\n1. Install the package:\n\n    ```bash\n    npm install --save sails-mysql-live-select\n    ```\n\n2. Add the connection settings to your `config/connections.js`:\n\n    ```javascript\n      liveMysql: {\n        adapter: 'sails-mysql-live-select',\n        host: '127.0.0.1',\n        // This user must have REPLICATION SLAVE, REPLICATION CLIENT and SELECT\n        // privileges.\n        user: 'USERNAME',\n        password: 'PASSWORD',\n        database: 'DATABASE',\n        // Other settings used by mysql-live-select\n        serverId: [Unique positive integer 1 - 2^32, default 1337]\n        minInterval: [Minimum time in milliseconds between refresh]\n      }\n    ```\n\n3. Add the adapter to be used on your models, for example in `config/models.js`:\n\n    ```javascript\n      connection: [ 'mysql', 'liveMysql' ],\n    ```\n\n## Usage\n\n### YourModel.liveFind(options, [condition])\n\nThis adapter adds a `liveFind` method to your models.\n\nArgument | Type | Description\n----------|------|-----------\n`options` | Object | Find options as defined by [Waterline Query Language](http://sailsjs.org/documentation/concepts/models-and-orm/query-language)\n`condition` | Function | Optional function for validating if result set should be refreshed on row change. See [condition function documentation for mysql-live-select](https://github.com/numtel/mysql-live-select#condition-function)\n\nThe `liveFind` method returns a [`LiveMysqlSelect` object as defined by mysql-live-select](https://github.com/numtel/mysql-live-select#livemysqlselect-object).\n\nFor example, listen for the `update` event in your controller actions to send changes to the client:\n\n```javascript\nvar myLiveSelect = MyModel.liveFind({},\n  function(row, newRow, rowDeleted) {\n    // Optional data invalidation callback\n    // Check if data is invalidated by this row change\n    console.log('Row data', row);\n    return true;\n  }\n).on('update',\n  function(diff, data) {\n    // Results have changed, send to client\n    sails.sockets.emit(req.socket.id, 'chatDiff', diff);\n  }\n);\n```\n\nWhen done listening for updates to a query, be sure to call the `stop()` method on the returned `LiveMysqlSelect` object to prevent memory leaks.\n\n## Running Tests\n\n```bash\n# Configure MySQL server settings\nvim test/config/connections.js\n# Run suite\nnpm test\n```\n\nTest execution code is in [`test/config/bootstrap.js`](test/config/bootstrap.js).\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumtel%2Fsails-mysql-live-select","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnumtel%2Fsails-mysql-live-select","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumtel%2Fsails-mysql-live-select/lists"}