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
Because `pg-native` is bound to [libpq](https://github.com/brianc/node-libpq) it is able to provide _sync_ operations for both connecting and queries. This is a bad idea in _non-blocking systems_ like web servers, but is exteremly convienent in scripts and bootstrapping applications - much the same way `fs.readFileSync` comes in handy.
82
82
83
83
```js
84
-
var Client =require('pg-native')
84
+
constClient=require('pg-native')
85
85
86
-
var client =newClient()
86
+
constclient=newClient()
87
87
client.connectSync()
88
88
89
-
//text queries
90
-
var rows =client.querySync('SELECT NOW() AS the_date')
pool.query('SELECT $1::text as name', ['brianc'], function (err, res) {
147
147
console.log(res.rows[0].name) // brianc
148
148
})
@@ -158,7 +158,7 @@ clients back to the pool after the query is done.
158
158
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 for years:
159
159
160
160
```js
161
-
var pool =newPool()
161
+
constpool=newPool()
162
162
pool.connect((err, client, done) => {
163
163
if (err) returndone(err)
164
164
@@ -178,8 +178,8 @@ When you are finished with the pool if all the clients are idle the pool will cl
178
178
will shutdown gracefully. If you don't want to wait for the timeout you can end the pool as follows:
179
179
180
180
```js
181
-
var pool =newPool()
182
-
var client =awaitpool.connect()
181
+
constpool=newPool()
182
+
constclient=awaitpool.connect()
183
183
console.log(awaitclient.query('select now()'))
184
184
client.release()
185
185
awaitpool.end()
@@ -194,7 +194,7 @@ The pool should be a __long-lived object__ in your application. Generally you'l
194
194
195
195
// correct usage: create the pool and let it live
196
196
// 'globally' here, controlling access to it through exported methods
197
-
var pool =newpg.Pool()
197
+
constpool=newpg.Pool()
198
198
199
199
// this is the right way to export the query method
0 commit comments