{"id":25838527,"url":"https://github.com/salesflare/hapi-plugin-mysql","last_synced_at":"2025-07-24T10:09:37.657Z","repository":{"id":25812290,"uuid":"29251324","full_name":"Salesflare/hapi-plugin-mysql","owner":"Salesflare","description":"Hapi plugin for MySQL","archived":false,"fork":false,"pushed_at":"2023-12-05T11:31:04.000Z","size":402,"stargazers_count":17,"open_issues_count":3,"forks_count":4,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-06-23T23:47:47.184Z","etag":null,"topics":["hapi","hapi-plugin","hapijs","mysql","plugin"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Salesflare.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-01-14T15:40:52.000Z","updated_at":"2024-09-19T16:12:39.000Z","dependencies_parsed_at":"2024-06-19T00:12:40.370Z","dependency_job_id":"3f72f79b-99cc-4be4-8f57-948ee658f117","html_url":"https://github.com/Salesflare/hapi-plugin-mysql","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"purl":"pkg:github/Salesflare/hapi-plugin-mysql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Salesflare%2Fhapi-plugin-mysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Salesflare%2Fhapi-plugin-mysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Salesflare%2Fhapi-plugin-mysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Salesflare%2Fhapi-plugin-mysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Salesflare","download_url":"https://codeload.github.com/Salesflare/hapi-plugin-mysql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Salesflare%2Fhapi-plugin-mysql/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266824085,"owners_count":23990152,"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","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["hapi","hapi-plugin","hapijs","mysql","plugin"],"created_at":"2025-03-01T03:49:46.848Z","updated_at":"2025-07-24T10:09:37.626Z","avatar_url":"https://github.com/Salesflare.png","language":"JavaScript","readme":"# hapi-plugin-mysql [![Build Status](https://travis-ci.org/Salesflare/hapi-plugin-mysql.svg?branch=master)](https://travis-ci.org/Salesflare/hapi-plugin-mysql)\n\n\u003e hapi plugin for MySQL\n\n## What\n\nAttaches a MySQL connection from a pool to every request.\n\n## How\n\nVia `request.app.db`.\nYou can also manually get a connection from the server via `server.getDb(function (err, connection) {})`.\n\n```javascript\nawait server.register({\n    plugin: require('hapi-plugin-mysql'),\n    options: {\n        host: \"localhost\",\n        user: \"root\",\n        password: \"\"\n    }\n});\n\nserver.route({\n    method: 'GET',\n    path: '/',\n    handler: async (request, h) =\u003e {\n\n        request.app.db.query(...);\n        return 'ok';\n    }\n});\n```\n\nThe options are the same options you can pass onto the `mysql` lib for making a connection. See \u003chttps://www.npmjs.com/package/mysql\u003e for more info on the `mysql` lib itself.\n\nThe keyword `db` is used because `connection` was used by `\u003c= hapi@16` and could have caused confusion/collision.\n\nIf you want more manual control or you want to use the same pool outside of the hapi part of your server\nyou can initialize the pool before the plugin registration by calling `await HapiPluginMysql.init(options)` and then call `require('hapi-plugin-mysql').getConnection` to get a connection from the pool.\nIf you still want to register the plugin (to get all the goodies) just don't pass any options to the plugin registration\nand it will use the same pool as first created.\nTo manually stop the pool call `await HapiPluginMySQL.stop()`.\nSee the tests for more granular use cases.\n\n## Catches\n\n- Transactions are no longer a part of this plugin and should be handled (with care) in your code\n\n## Testing\n\n- almost 100% code coverage! If you know how to test these last case please do let me know or PR :O\n- The tests requires you to have a `test` db with a table  `test` and `{user: root, password: \"\"}`.\n- See `.travis.yml` and the tests for more info.\n\n## Changelog\n\nSee the [releases](https://github.com/Salesflare/hapi-plugin-mysql/releases) page\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalesflare%2Fhapi-plugin-mysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsalesflare%2Fhapi-plugin-mysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalesflare%2Fhapi-plugin-mysql/lists"}