Skip to content

Instantly share code, notes, and snippets.

@doron2402
Created August 10, 2017 16:51
Show Gist options
  • Save doron2402/83634115536721118153dff10b4655b1 to your computer and use it in GitHub Desktop.
Save doron2402/83634115536721118153dff10b4655b1 to your computer and use it in GitHub Desktop.
hapi-plugin-pg - access plugin via server object
const Query = ‘select * from users’;
const pool = server.plugins[‘hapi - plugin - pg’].pg;
pool.query(Query, (err, res) => { 
if (err) {  //do something
 } 
pool.end(); // this is important 
 
return res;
});
// You can also use promises
const Query = ‘select * from users’;
const pool = server.plugins[‘hapi - plugin - pg’].pg;
pool.query(Query).then((res) => {
// Do something with the result
}).catch((err) => {
//Handle error
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment