Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/floatdrop/pg-parade
https://github.com/floatdrop/pg-parade
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/floatdrop/pg-parade
- Owner: floatdrop
- License: mit
- Created: 2016-07-26T13:34:48.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-09T09:21:59.000Z (almost 8 years ago)
- Last Synced: 2024-10-26T21:11:55.884Z (3 months ago)
- Language: JavaScript
- Size: 411 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/floatdrop/pg-parade.svg?branch=master)](https://travis-ci.org/floatdrop/pg-parade)
This module wraps [pg-promise](https://github.com/vitaly-t/pg-promise) for read/write replica support.
## Install
```
$ npm install --save pg-parade
```## Usage
```js
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](https://github.com/vitaly-t/pg-promise#advanced) 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](http://github.com/floatdrop)