All Projects → Salesflare → hapi-plugin-mysql

Salesflare / hapi-plugin-mysql

Licence: MIT license
Hapi plugin for MySQL

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to hapi-plugin-mysql

hapi-now-auth
Hapi token auth for bearer and jwt
Stars: ✭ 43 (+152.94%)
Mutual labels:  hapi, hapijs, hapi-plugin
hapi-good-winston
A good reporter to send and log events with winston
Stars: ✭ 21 (+23.53%)
Mutual labels:  hapi, hapijs, hapi-plugin
hapi-cli
CLI to build API with Hapi, mongodb and mongoose. Work with Hapi V17.
Stars: ✭ 36 (+111.76%)
Mutual labels:  hapi, hapijs
typesafe-hapi
Typechecking for HapiJS based on Joi schemas!
Stars: ✭ 21 (+23.53%)
Mutual labels:  hapi, hapijs
hapi-routes
Hapi plugin for registering routes
Stars: ✭ 12 (-29.41%)
Mutual labels:  hapijs, hapi-plugin
hapi-statsd
A hapi plugin for sending request round trip metrics to statsd
Stars: ✭ 29 (+70.59%)
Mutual labels:  hapi, hapi-plugin
hapi-mongo-models
📦 A hapi plugin for `mongo-models`
Stars: ✭ 101 (+494.12%)
Mutual labels:  hapi, hapi-plugin
hapi-sentry
A hapi plugin for request error logging to Sentry
Stars: ✭ 24 (+41.18%)
Mutual labels:  hapi, hapi-plugin
hapi-sequelizejs
A hapi.js plugin to connect with Sequelize ORM
Stars: ✭ 56 (+229.41%)
Mutual labels:  hapi, hapi-plugin
hapi-dev-errors
A hapi plugin to return better error details and skip the look at command line to catch the issue.
Stars: ✭ 58 (+241.18%)
Mutual labels:  hapi, hapi-plugin
hapi-docs
Beautiful API documentation generator for Hapi using Vue
Stars: ✭ 64 (+276.47%)
Mutual labels:  hapi, hapi-plugin
hapi-moon
Hassle-free and production ready hapi.js Server boilerplate
Stars: ✭ 23 (+35.29%)
Mutual labels:  hapi, hapijs
nodejs-tutorials-hapi
Examples for the hapi tutorial series within the Future Studio University
Stars: ✭ 70 (+311.76%)
Mutual labels:  hapi, hapijs
Crashlyzer
Crash viewer web application for displaying the crashes reported by rn-crash-reporter components from React Native mobile applications.
Stars: ✭ 59 (+247.06%)
Mutual labels:  hapi, hapijs
sapper-authentication-demo
A demonstration of Auth with Sapper + JWT + Server Side Rendering + RBAC
Stars: ✭ 102 (+500%)
Mutual labels:  hapi, hapijs
good-sentry
Sentry broadcasting for good process monitor
Stars: ✭ 15 (-11.76%)
Mutual labels:  hapi, hapijs
H2o2
Proxy handler for hapi.js
Stars: ✭ 158 (+829.41%)
Mutual labels:  hapi
Hapi React Views
📦 A hapi view engine for React components
Stars: ✭ 234 (+1276.47%)
Mutual labels:  hapi
Hapi Api
Lean hapi API Boilerplate with an opinionated view on project structure
Stars: ✭ 148 (+770.59%)
Mutual labels:  hapi
Promster
⏰A Prometheus exporter for Hapi, express and Marble.js servers to automatically measure request timings 📊
Stars: ✭ 146 (+758.82%)
Mutual labels:  hapi

hapi-plugin-mysql Build Status

hapi plugin for MySQL

What

Attaches a MySQL connection from a pool to every request.

How

Via request.app.db. You can also manually get a connection from the server via server.getDb(function (err, connection) {}).

await server.register({
    plugin: require('hapi-plugin-mysql'),
    options: {
        host: "localhost",
        user: "root",
        password: ""
    }
});

server.route({
    method: 'GET',
    path: '/',
    handler: async (request, h) => {

        request.app.db.query(...);
        return 'ok';
    }
});

The options are the same options you can pass onto the mysql lib for making a connection. See https://www.npmjs.com/package/mysql for more info on the mysql lib itself.

The keyword db is used because connection was used by <= hapi@16 and could have caused confusion/collision.

If you want more manual control or you want to use the same pool outside of the hapi part of your server you 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. If you still want to register the plugin (to get all the goodies) just don't pass any options to the plugin registration and it will use the same pool as first created. To manually stop the pool call await HapiPluginMySQL.stop(). See the tests for more granular use cases.

Catches

  • Transactions are no longer a part of this plugin and should be handled (with care) in your code

Testing

  • almost 100% code coverage! If you know how to test these last case please do let me know or PR :O
  • The tests requires you to have a test db with a table test and {user: root, password: ""}.
  • See .travis.yml and the tests for more info.

Changelog

See the releases page

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].