https://github.com/michaellzc/egg-pg
PostgreSQL Plugin which supports pooling for egg.
https://github.com/michaellzc/egg-pg
egg-pg egg-plugin eggjs node-postgres pg postgres postgresql
Last synced: 4 months ago
JSON representation
PostgreSQL Plugin which supports pooling for egg.
- Host: GitHub
- URL: https://github.com/michaellzc/egg-pg
- Owner: michaellzc
- License: mit
- Created: 2018-02-02T01:59:13.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-06-01T20:28:08.000Z (over 5 years ago)
- Last Synced: 2025-06-03T11:56:06.405Z (5 months ago)
- Topics: egg-pg, egg-plugin, eggjs, node-postgres, pg, postgres, postgresql
- Language: JavaScript
- Homepage:
- Size: 673 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# egg-pg
[](https://david-dm.org/ExiaSR/egg-pg)
PostgreSQL plugin which supports pooling for egg.
This plugin exposes the [Pool](https://node-postgres.com/api/pool) object from [node-postgres](https://node-postgres.com) at `app.pg`.
Latest version of [node-postgres](https://node-postgres.com): **7.10.0**
## Install
`npm i @exiasr/egg-pg``yarn add @exiasr/egg-pg`
## Configuration
### Enable plugin
```js
// {app_root}/config/plugin.js
exports.pg = {
enable: true,
package: '@exiasr/egg-pg',
};
```
### Sample```js
// {app_root}/config/config.default.js
exports.pg = {
user: 'root',
host: 'localhost',
database: 'compose',
password: 'supersecure',
port: '27017',
};
```
### Single database instance
```js
// {app_root}/config/config.default.js
exports.pg = {
connectionString: 'postgres://:@:/',
}
```
### Multiple database instance
```js
// {app_root}/config/config.default.js
exports.pg = {
clients: {
client1: {
connectionString: 'postgres://root:supersecure@localhost:27017/compose',
},
client2: {
connectionString: 'postgres://root:supersecure@localhost:27018/compose',
},
},
};
```
see [config/config.default.js](config/config.default.js) for more detail.## Usage
### Single database instance
```js
const { app } = this;
const pool = app.pg;
const { rows } = await pool.query('SELECT NOW()');
```### Multiple database instance
```js
const { app } = this;
const pool = app.pg.get('');
const { rows } = await pool.query('SELECT NOW()');
```## License
[MIT](LICENSE)