You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
__pro tip:__ unless you need to run a transaction (which requires a single client for multiple queries) or you
81
+
have some other edge case like [streaming rows](https://github.com/brianc/node-pg-query-stream) or using a [cursor](https://github.com/brianc/node-pg-cursor)
82
+
you should almost always just use `pool.query`. Its easy, it does the right thing :tm:, and wont ever forget to return
83
+
clients back to the pool after the query is done.
84
+
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:
60
86
61
87
```js
62
88
constpool=newPool()
63
89
pool.connect((err, client, done) => {
64
90
if (err) returndone(err)
65
-
91
+
66
92
client.query('SELECT $1::text as name', ['pg-pool'], (err, res) => {
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!
103
+
76
104
When you are finished with the pool if all the clients are idle the pool will close them after `config.idleTimeoutMillis` and your app
77
105
will shutdown gracefully. If you don't want to wait for the timeout you can end the pool as follows:
78
106
@@ -88,6 +116,10 @@ await pool.end()
88
116
89
117
To run tests clone the repo, `npm i` in the working dir, and then run `npm test`
90
118
119
+
## contributions
120
+
121
+
I love contributions. Please make sure they have tests, and submit a PR. If you're not sure if the issue is worth it or will be accepted it never hurts to open an issue to begin the conversation. Don't forget to follow me on twitter at [@briancarlson](https://twitter.com/briancarlson) - I generally announce any noteworthy updates there.
0 commit comments