hapi-pg-pool
v1.0.0
Published
Expose postgres connection pooling to request handlers.
Downloads
6
Maintainers
Readme
Hapi PG Pool
Create a PostgreSQL connection pool available to Hapi request handlers.
Implements pooling with the pg-pool
package.
Using
Install from NPM
npm i hapi-pg-pool -S
Ensure you have either your favourite PostgreSQL client dependency, or install the
pg
clientnpm i pg -S
Register the extension
server.register({ register: require('hapi-pg-pool'), options: { database: 'postgres', user: 'postgres', password: 'postgres' } }, function (err) { if (err) { throw err } // server.route(...) })
Use the pool in your handlers
server.route({ method: 'GET', path: '/', handler: function(request, reply) { console.log('sleepy...'); request.pg.query('SELECT pg_sleep(1)', function (err, result) { if (err) { server.log('error', err) return reply(err) } reply('awake!') }) } });
Refer to pg-pool
for more ways to use the request.pg
(Pool) object.
License
MIT.