Native Bindings
Native bindings between node.js & libpq are provided by the node-pg-native package. node-postgres can consume this package & use the native bindings to access the PostgreSQL server while giving you the same interface that is used with the JavaScript version of the library.
To use the native bindings first you'll need to install them:
$ npm install pg pg-native
Once pg-native
is installed instead of requiring a Client
or Pool
constructor from pg
you do the following:
const { Client, Pool } = require('pg').native
When you access the .native
property on require('pg')
it will automatically require the pg-native
package and wrap it in the same API.
Some of the modules using advanced features of PostgreSQL such as pg-query-stream, pg-cursor,and pg-copy-streams need to operate directly on the binary stream and therefore are incompatible with the native bindings.