0.4.3 • Published 7 years ago

pg-parade v0.4.3

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

Build Status

This module wraps pg-promise for read/write replica support.

Install

$ npm install --save pg-parade

Usage

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

API

pgParade(options)

options

Initialization options from pg-promise.

Returns instance of initialized database factory.

pgSelect(replicas)

Returns Database object with two operations scopes:

  • read - query will be executed on closest read server
  • write - query will be executed on closest write server

replicas

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.

Transactions

When calling tx method, callback will recieve proxy object with read and write properties, but all read requests will be executed on write replica.

License

MIT © Vsevolod Strukchinsky

0.4.3

7 years ago

0.4.2

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago