This module wraps pg-promise for read/write replica support.
$ npm install --save pg-parade
const pgp = require('pg-parade')();
const db = pgp({
write: 'postgres://localhost:5432/postgres',
read: 'postgres://localhost:5433/postgres'
});
db.write.query('INSERT INTO test VALUES (1)'); // Will be executed on write server
db.read.query('SELECT * FROM test'); // Will be executed on read server
Initialization options from pg-promise
.
Returns instance of initialized database factory.
Returns Database object with two operations scopes:
read
- query will be executed on closest read serverwrite
- query will be executed on closest write server
Type: Object
, Function
Object with read
and write
connection strings.
If cluster
is type of Function โ then it should return a promise, resolving to an Object.
When calling tx
method, callback will recieve proxy object with read
and write
properties, but all read
requests will be executed on write
replica.
MIT ยฉ Vsevolod Strukchinsky