Skip to content

Commit d735385

Browse files
authored
Update README.md
1 parent 5c88bd6 commit d735385

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ npm i pg-pool pg
88

99
## use
1010

11+
### create
12+
1113
to use pg-pool you must first create an instance of a pool
1214

1315
```js
@@ -40,6 +42,8 @@ const PgNativeClient = require('pg-native')
4042
const pgNativePool = new Pool({ Client: PgNativeClient })
4143
```
4244

45+
### acquire clients with a promise
46+
4347
pg-pool supports a fully promise-based api for acquiring clients
4448

4549
```js
@@ -56,6 +60,8 @@ pool.connect().then(client => {
5660
})
5761
```
5862

63+
### plays nice with async/await
64+
5965
this ends up looking much nicer if you're using [co](https://github.com/tj/co) or async/await:
6066

6167
```js
@@ -69,6 +75,8 @@ try {
6975
}
7076
```
7177

78+
### your new favorite helper method
79+
7280
because its so common to just run a query and return the client to the pool afterward pg-pool has this built-in:
7381

7482
```js
@@ -82,7 +90,9 @@ have some other edge case like [streaming rows](https://github.com/brianc/node-p
8290
you should almost always just use `pool.query`. Its easy, it does the right thing :tm:, and wont ever forget to return
8391
clients back to the pool after the query is done.
8492

85-
pg-pool still and will always support the traditional callback api for acquiring a client that node-postgres has shipped with internally for years:
93+
### drop-in backwards compatible
94+
95+
pg-pool still and will always support the traditional callback api for acquiring a client. This is the exact API node-postgres has shipped with internally for years:
8696

8797
```js
8898
const pool = new Pool()
@@ -101,6 +111,8 @@ pool.connect((err, client, done) => {
101111

102112
That means you can drop pg-pool into your app and 99% of the cases you wont even notice a difference. In fact, very soon I will be using pg-pool internally within node-postgres itself!
103113

114+
### shut it down
115+
104116
When you are finished with the pool if all the clients are idle the pool will close them after `config.idleTimeoutMillis` and your app
105117
will shutdown gracefully. If you don't want to wait for the timeout you can end the pool as follows:
106118

0 commit comments

Comments
 (0)