Why not simply use [pg-promise](https://github.com/vitaly-t/pg-promise) that already has all of it, and much more?