hapi-pg
Hapi.js plugin for postgres (Using PG 7.X.X)
Install
$ npm install hapi-plugin-pg
Usage
Register
- Register the plugin with username/password/host/port/database
const plugin = register: options: user: 'username' password: 'password' port: 5432 host: 'localhost' database: 'test_db' attach: 'onPreHandler' // Hapi.js events detach: 'tail' // Hapi.js events ;
- Register with connection String
const plugin = register: options: connectionString: 'postgres://username:password@localhost/database' ;
- Make sure to register the plugin with
connectionString
ORuser
/password
/host
/port
/database
not both! this will throw an error. - attach event will ask from the Postgres pool for a connection.
- detach event will return the Postges connection to the pool.
Query
- Using
request
object:
requestpgclient;
- Using the
server
object:
serverplugins'hapi-plugin-pg'pg;
Example
server;
Contribute
Feel free to create a pr just make sure to add tests
License
MIT