Skip to content

Commit 93aa1ba

Browse files
chore: replace var with const in md files (#3446)
1 parent 9e7a5d9 commit 93aa1ba

File tree

5 files changed

+68
-68
lines changed

5 files changed

+68
-68
lines changed

docs/pages/guides/upgrading.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pg.end()
5050
// new way, available since 6.0.0:
5151

5252
// create a pool
53-
var pool = new pg.Pool()
53+
const pool = new pg.Pool()
5454

5555
// connection using created pool
5656
pool.connect(function (err, client, done) {

packages/pg-connection-string/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ MIT License
1515
## Usage
1616

1717
```js
18-
var parse = require('pg-connection-string').parse;
18+
const parse = require('pg-connection-string').parse;
1919

20-
var config = parse('postgres://someuser:somepassword@somehost:381/somedatabase')
20+
const config = parse('postgres://someuser:somepassword@somehost:381/somedatabase')
2121
```
2222

2323
The resulting config contains a subset of the following properties:

packages/pg-native/README.md

+30-30
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,40 @@ $ npm i pg-native
3030
### async
3131

3232
```js
33-
var Client = require('pg-native')
33+
const Client = require('pg-native')
3434

35-
var client = new Client();
35+
const client = new Client();
3636
client.connect(function(err) {
3737
if(err) throw err
3838

39-
//text queries
39+
// text queries
4040
client.query('SELECT NOW() AS the_date', function(err, rows) {
4141
if(err) throw err
4242

43-
console.log(rows[0].the_date) //Tue Sep 16 2014 23:42:39 GMT-0400 (EDT)
43+
console.log(rows[0].the_date) // Tue Sep 16 2014 23:42:39 GMT-0400 (EDT)
4444

45-
//parameterized statements
45+
// parameterized statements
4646
client.query('SELECT $1::text as twitter_handle', ['@briancarlson'], function(err, rows) {
4747
if(err) throw err
4848

4949
console.log(rows[0].twitter_handle) //@briancarlson
5050
})
5151

52-
//prepared statements
52+
// prepared statements
5353
client.prepare('get_twitter', 'SELECT $1::text as twitter_handle', 1, function(err) {
5454
if(err) throw err
5555

56-
//execute the prepared, named statement
56+
// execute the prepared, named statement
5757
client.execute('get_twitter', ['@briancarlson'], function(err, rows) {
5858
if(err) throw err
5959

6060
console.log(rows[0].twitter_handle) //@briancarlson
6161

62-
//execute the prepared, named statement again
62+
// execute the prepared, named statement again
6363
client.execute('get_twitter', ['@realcarrotfacts'], function(err, rows) {
6464
if(err) throw err
6565

66-
console.log(rows[0].twitter_handle) //@realcarrotfacts
66+
console.log(rows[0].twitter_handle) // @realcarrotfacts
6767

6868
client.end(function() {
6969
console.log('ended')
@@ -81,27 +81,27 @@ client.connect(function(err) {
8181
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.
8282

8383
```js
84-
var Client = require('pg-native')
84+
const Client = require('pg-native')
8585

86-
var client = new Client()
86+
const client = new Client()
8787
client.connectSync()
8888

89-
//text queries
90-
var rows = client.querySync('SELECT NOW() AS the_date')
91-
console.log(rows[0].the_date) //Tue Sep 16 2014 23:42:39 GMT-0400 (EDT)
89+
// text queries
90+
const rows = client.querySync('SELECT NOW() AS the_date')
91+
console.log(rows[0].the_date) // Tue Sep 16 2014 23:42:39 GMT-0400 (EDT)
9292

93-
//parameterized queries
94-
var rows = client.querySync('SELECT $1::text as twitter_handle', ['@briancarlson'])
95-
console.log(rows[0].twitter_handle) //@briancarlson
93+
// parameterized queries
94+
const rows = client.querySync('SELECT $1::text as twitter_handle', ['@briancarlson'])
95+
console.log(rows[0].twitter_handle) // @briancarlson
9696

97-
//prepared statements
97+
// prepared statements
9898
client.prepareSync('get_twitter', 'SELECT $1::text as twitter_handle', 1)
9999

100-
var rows = client.executeSync('get_twitter', ['@briancarlson'])
101-
console.log(rows[0].twitter_handle) //@briancarlson
100+
const rows = client.executeSync('get_twitter', ['@briancarlson'])
101+
console.log(rows[0].twitter_handle) // @briancarlson
102102

103-
var rows = client.executeSync('get_twitter', ['@realcarrotfacts'])
104-
console.log(rows[0].twitter_handle) //@realcarrotfacts
103+
const rows = client.executeSync('get_twitter', ['@realcarrotfacts'])
104+
console.log(rows[0].twitter_handle) // @realcarrotfacts
105105
```
106106

107107
## api
@@ -125,14 +125,14 @@ Returns an `Error` to the `callback` if the connection was unsuccessful. `callb
125125
##### example
126126

127127
```js
128-
var client = new Client()
128+
const client = new Client()
129129
client.connect(function(err) {
130130
if(err) throw err
131131

132132
console.log('connected!')
133133
})
134134

135-
var client2 = new Client()
135+
const client2 = new Client()
136136
client2.connect('postgresql://user:password@host:5432/database?param=value', function(err) {
137137
if(err) throw err
138138

@@ -147,7 +147,7 @@ Execute a query with the text of `queryText` and _optional_ parameters specified
147147
##### example
148148

149149
```js
150-
var client = new Client()
150+
const client = new Client()
151151
client.connect(function(err) {
152152
if (err) throw err
153153

@@ -175,7 +175,7 @@ Prepares a _named statement_ for later execution. You _must_ supply the name of
175175
##### example
176176

177177
```js
178-
var client = new Client()
178+
const client = new Client()
179179
client.connect(function(err) {
180180
if(err) throw err
181181

@@ -197,7 +197,7 @@ Executes a previously prepared statement on this client with the name of `statem
197197

198198

199199
```js
200-
var client = new Client()
200+
const client = new Client()
201201
client.connect(function(err) {
202202
if(err) throw err
203203

@@ -221,7 +221,7 @@ Ends the connection. Calls the _optional_ callback when the connection is termin
221221
##### example
222222

223223
```js
224-
var client = new Client()
224+
const client = new Client()
225225
client.connect(function(err) {
226226
if(err) throw err
227227
client.end(function() {
@@ -236,9 +236,9 @@ Cancels the active query on the client. Callback receives an error if there was
236236

237237
##### example
238238
```js
239-
var client = new Client()
239+
const client = new Client()
240240
client.connectSync()
241-
//sleep for 100 seconds
241+
// sleep for 100 seconds
242242
client.query('select pg_sleep(100)', function(err) {
243243
console.log(err) // [Error: ERROR: canceling statement due to user request]
244244
})

packages/pg-pool/README.md

+32-32
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ npm i pg-pool pg
1515
to use pg-pool you must first create an instance of a pool
1616

1717
```js
18-
var Pool = require('pg-pool')
18+
const Pool = require('pg-pool')
1919

2020
// by default the pool uses the same
2121
// configuration as whatever `pg` version you have installed
22-
var pool = new Pool()
22+
const pool = new Pool()
2323

2424
// you can pass properties to the pool
2525
// these properties are passed unchanged to both the node-postgres Client constructor
2626
// and the node-pool (https://github.com/coopernurse/node-pool) constructor
2727
// allowing you to fully configure the behavior of both
28-
var pool2 = new Pool({
28+
const pool2 = new Pool({
2929
database: 'postgres',
3030
user: 'brianc',
3131
password: 'secret!',
@@ -37,14 +37,14 @@ var pool2 = new Pool({
3737
maxUses: 7500, // close (and replace) a connection after it has been used 7500 times (see below for discussion)
3838
})
3939

40-
//you can supply a custom client constructor
41-
//if you want to use the native postgres client
42-
var NativeClient = require('pg').native.Client
43-
var nativePool = new Pool({ Client: NativeClient })
40+
// you can supply a custom client constructor
41+
// if you want to use the native postgres client
42+
const NativeClient = require('pg').native.Client
43+
const nativePool = new Pool({ Client: NativeClient })
4444

45-
//you can even pool pg-native clients directly
46-
var PgNativeClient = require('pg-native')
47-
var pgNativePool = new Pool({ Client: PgNativeClient })
45+
// you can even pool pg-native clients directly
46+
const PgNativeClient = require('pg-native')
47+
const pgNativePool = new Pool({ Client: PgNativeClient })
4848
```
4949

5050
##### Note:
@@ -86,7 +86,7 @@ const pool = new Pool(config);
8686
pg-pool supports a fully promise-based api for acquiring clients
8787

8888
```js
89-
var pool = new Pool()
89+
const pool = new Pool()
9090
pool.connect().then(client => {
9191
client.query('select $1::text as name', ['pg-pool']).then(res => {
9292
client.release()
@@ -106,10 +106,10 @@ this ends up looking much nicer if you're using [co](https://github.com/tj/co) o
106106
```js
107107
// with async/await
108108
(async () => {
109-
var pool = new Pool()
110-
var client = await pool.connect()
109+
const pool = new Pool()
110+
const client = await pool.connect()
111111
try {
112-
var result = await client.query('select $1::text as name', ['brianc'])
112+
const result = await client.query('select $1::text as name', ['brianc'])
113113
console.log('hello from', result.rows[0])
114114
} finally {
115115
client.release()
@@ -118,9 +118,9 @@ this ends up looking much nicer if you're using [co](https://github.com/tj/co) o
118118

119119
// with co
120120
co(function * () {
121-
var client = yield pool.connect()
121+
const client = yield pool.connect()
122122
try {
123-
var result = yield client.query('select $1::text as name', ['brianc'])
123+
const result = yield client.query('select $1::text as name', ['brianc'])
124124
console.log('hello from', result.rows[0])
125125
} finally {
126126
client.release()
@@ -133,16 +133,16 @@ co(function * () {
133133
because its so common to just run a query and return the client to the pool afterward pg-pool has this built-in:
134134

135135
```js
136-
var pool = new Pool()
137-
var time = await pool.query('SELECT NOW()')
138-
var name = await pool.query('select $1::text as name', ['brianc'])
136+
const pool = new Pool()
137+
const time = await pool.query('SELECT NOW()')
138+
const name = await pool.query('select $1::text as name', ['brianc'])
139139
console.log(name.rows[0].name, 'says hello at', time.rows[0].now)
140140
```
141141

142142
you can also use a callback here if you'd like:
143143

144144
```js
145-
var pool = new Pool()
145+
const pool = new Pool()
146146
pool.query('SELECT $1::text as name', ['brianc'], function (err, res) {
147147
console.log(res.rows[0].name) // brianc
148148
})
@@ -158,7 +158,7 @@ clients back to the pool after the query is done.
158158
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:
159159

160160
```js
161-
var pool = new Pool()
161+
const pool = new Pool()
162162
pool.connect((err, client, done) => {
163163
if (err) return done(err)
164164

@@ -178,8 +178,8 @@ When you are finished with the pool if all the clients are idle the pool will cl
178178
will shutdown gracefully. If you don't want to wait for the timeout you can end the pool as follows:
179179

180180
```js
181-
var pool = new Pool()
182-
var client = await pool.connect()
181+
const pool = new Pool()
182+
const client = await pool.connect()
183183
console.log(await client.query('select now()'))
184184
client.release()
185185
await pool.end()
@@ -194,7 +194,7 @@ The pool should be a __long-lived object__ in your application. Generally you'l
194194

195195
// correct usage: create the pool and let it live
196196
// 'globally' here, controlling access to it through exported methods
197-
var pool = new pg.Pool()
197+
const pool = new pg.Pool()
198198

199199
// this is the right way to export the query method
200200
module.exports.query = (text, values) => {
@@ -208,7 +208,7 @@ module.exports.connect = () => {
208208
// every time we called 'connect' to get a new client?
209209
// that's a bad thing & results in creating an unbounded
210210
// number of pools & therefore connections
211-
var aPool = new pg.Pool()
211+
const aPool = new pg.Pool()
212212
return aPool.connect()
213213
}
214214
```
@@ -245,7 +245,7 @@ Example:
245245
const Pool = require('pg-pool')
246246
const pool = new Pool()
247247

248-
var count = 0
248+
const count = 0
249249

250250
pool.on('connect', client => {
251251
client.count = count++
@@ -272,20 +272,20 @@ Example:
272272
This allows you to count the number of clients which have ever been acquired from the pool.
273273

274274
```js
275-
var Pool = require('pg-pool')
276-
var pool = new Pool()
275+
const Pool = require('pg-pool')
276+
const pool = new Pool()
277277

278-
var acquireCount = 0
278+
const acquireCount = 0
279279
pool.on('acquire', function (client) {
280280
acquireCount++
281281
})
282282

283-
var connectCount = 0
283+
const connectCount = 0
284284
pool.on('connect', function () {
285285
connectCount++
286286
})
287287

288-
for (var i = 0; i < 200; i++) {
288+
for (let i = 0; i < 200; i++) {
289289
pool.query('SELECT NOW()')
290290
}
291291

@@ -324,7 +324,7 @@ if (typeof Promise == 'undefined') {
324324
You can use any other promise implementation you'd like. The pool also allows you to configure the promise implementation on a per-pool level:
325325

326326
```js
327-
var bluebirdPool = new Pool({
327+
const bluebirdPool = new Pool({
328328
Promise: require('bluebird')
329329
})
330330
```

packages/pg-query-stream/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ _requires pg>=2.8.1_
1515

1616
```js
1717
const pg = require('pg')
18-
var pool = new pg.Pool()
18+
const pool = new pg.Pool()
1919
const QueryStream = require('pg-query-stream')
2020
const JSONStream = require('JSONStream')
2121

22-
//pipe 1,000,000 rows to stdout without blowing up your memory usage
22+
// pipe 1,000,000 rows to stdout without blowing up your memory usage
2323
pool.connect((err, client, done) => {
2424
if (err) throw err
2525
const query = new QueryStream('SELECT * FROM generate_series(0, $1) num', [1000000])
2626
const stream = client.query(query)
27-
//release the client when the stream is finished
27+
// release the client when the stream is finished
2828
stream.on('end', done)
2929
stream.pipe(JSONStream.stringify()).pipe(process.stdout)
3030
})

0 commit comments

Comments
 (0)