pg-promise returns integers as strings

There is a lot below that’s been accumulating historically. But if you are using Node.js v10.4.0 or later, you can skip all this, and jump into section UPDATE-2 at the bottom. This is indeed the standard behavior. bigint is 64-bit, and all 64-bit integers are returned by the underlying node-postgres driver as type string, while … Read more

Where should I initialize pg-promise

You need to initialize the database connection only once. If it is to be shared between modules, then put it into its own module file, like this: const initOptions = { // initialization options; }; const pgp = require(‘pg-promise’)(initOptions); const cn = ‘postgres://username:password@host:port/database’; const db = pgp(cn); module.exports = { pgp, db }; See supported … Read more

Multi-row insert with pg-promise

I’m the author of pg-promise. In older versions of the library this was covered by simplified examples within the Performance Boost article, which is still a good read when writing high-performance database applications. The newer approach is to rely on the helpers namespace, which is ultimately flexible, and optimised for performance. const pgp = require(‘pg-promise’)({ … Read more