Created
August 10, 2017 16:51
-
-
Save doron2402/83634115536721118153dff10b4655b1 to your computer and use it in GitHub Desktop.
hapi-plugin-pg - access plugin via server object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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