Wrap requests with a Postgres connection using promises.
We use the pg-promise
(pg-promise
)
$ npm install hapi-pg-promise
In your request handlers you'll have access to request.db
which you
can use to make DB requests.
server.plugins['hapi-pg-promise'].db
is available outside of request
handlers.
Current version works with Hapi 17.x.x. For older versions use 1.0.0 of hapi-pg-promise.
const hapiPgPromise = require('hapi-pg-promise');
const plugin = {
plugin: hapiPgPromise,
options: {
cn: 'postgres://username:password@host:port/database',
settings: {
// pg-promise options
}
}
};
server.register(plugin);
MIT