Skip to content

chore: replace var with const in md files #3446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/pages/guides/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pg.end()
// new way, available since 6.0.0:

// create a pool
var pool = new pg.Pool()
const pool = new pg.Pool()

// connection using created pool
pool.connect(function (err, client, done) {
Expand Down
4 changes: 2 additions & 2 deletions packages/pg-connection-string/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ MIT License
## Usage

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

var config = parse('postgres://someuser:somepassword@somehost:381/somedatabase')
const config = parse('postgres://someuser:somepassword@somehost:381/somedatabase')
```

The resulting config contains a subset of the following properties:
Expand Down
60 changes: 30 additions & 30 deletions packages/pg-native/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,40 @@ $ npm i pg-native
### async

```js
var Client = require('pg-native')
const Client = require('pg-native')

var client = new Client();
const client = new Client();
client.connect(function(err) {
if(err) throw err

//text queries
// text queries
client.query('SELECT NOW() AS the_date', function(err, rows) {
if(err) throw err

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

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

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

//prepared statements
// prepared statements
client.prepare('get_twitter', 'SELECT $1::text as twitter_handle', 1, function(err) {
if(err) throw err

//execute the prepared, named statement
// execute the prepared, named statement
client.execute('get_twitter', ['@briancarlson'], function(err, rows) {
if(err) throw err

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

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

console.log(rows[0].twitter_handle) //@realcarrotfacts
console.log(rows[0].twitter_handle) // @realcarrotfacts

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

```js
var Client = require('pg-native')
const Client = require('pg-native')

var client = new Client()
const client = new Client()
client.connectSync()

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

//parameterized queries
var rows = client.querySync('SELECT $1::text as twitter_handle', ['@briancarlson'])
console.log(rows[0].twitter_handle) //@briancarlson
// parameterized queries
const rows = client.querySync('SELECT $1::text as twitter_handle', ['@briancarlson'])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: these examples can’t run all together anymore.

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

//prepared statements
// prepared statements
client.prepareSync('get_twitter', 'SELECT $1::text as twitter_handle', 1)

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

var rows = client.executeSync('get_twitter', ['@realcarrotfacts'])
console.log(rows[0].twitter_handle) //@realcarrotfacts
const rows = client.executeSync('get_twitter', ['@realcarrotfacts'])
console.log(rows[0].twitter_handle) // @realcarrotfacts
```

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

```js
var client = new Client()
const client = new Client()
client.connect(function(err) {
if(err) throw err

console.log('connected!')
})

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

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

```js
var client = new Client()
const client = new Client()
client.connect(function(err) {
if (err) throw err

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

```js
var client = new Client()
const client = new Client()
client.connect(function(err) {
if(err) throw err

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


```js
var client = new Client()
const client = new Client()
client.connect(function(err) {
if(err) throw err

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

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

##### example
```js
var client = new Client()
const client = new Client()
client.connectSync()
//sleep for 100 seconds
// sleep for 100 seconds
client.query('select pg_sleep(100)', function(err) {
console.log(err) // [Error: ERROR: canceling statement due to user request]
})
Expand Down
64 changes: 32 additions & 32 deletions packages/pg-pool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ npm i pg-pool pg
to use pg-pool you must first create an instance of a pool

```js
var Pool = require('pg-pool')
const Pool = require('pg-pool')

// by default the pool uses the same
// configuration as whatever `pg` version you have installed
var pool = new Pool()
const pool = new Pool()

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

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

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

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

```js
var pool = new Pool()
const pool = new Pool()
pool.connect().then(client => {
client.query('select $1::text as name', ['pg-pool']).then(res => {
client.release()
Expand All @@ -106,10 +106,10 @@ this ends up looking much nicer if you're using [co](https://github.com/tj/co) o
```js
// with async/await
(async () => {
var pool = new Pool()
var client = await pool.connect()
const pool = new Pool()
const client = await pool.connect()
try {
var result = await client.query('select $1::text as name', ['brianc'])
const result = await client.query('select $1::text as name', ['brianc'])
console.log('hello from', result.rows[0])
} finally {
client.release()
Expand All @@ -118,9 +118,9 @@ this ends up looking much nicer if you're using [co](https://github.com/tj/co) o

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

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

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

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

```js
var pool = new Pool()
const pool = new Pool()
pool.connect((err, client, done) => {
if (err) return done(err)

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

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

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

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

var count = 0
const count = 0

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

```js
var Pool = require('pg-pool')
var pool = new Pool()
const Pool = require('pg-pool')
const pool = new Pool()

var acquireCount = 0
const acquireCount = 0
pool.on('acquire', function (client) {
acquireCount++
})

var connectCount = 0
const connectCount = 0
pool.on('connect', function () {
connectCount++
})

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

Expand Down Expand Up @@ -324,7 +324,7 @@ if (typeof Promise == 'undefined') {
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:

```js
var bluebirdPool = new Pool({
const bluebirdPool = new Pool({
Promise: require('bluebird')
})
```
Expand Down
6 changes: 3 additions & 3 deletions packages/pg-query-stream/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ _requires pg>=2.8.1_

```js
const pg = require('pg')
var pool = new pg.Pool()
const pool = new pg.Pool()
const QueryStream = require('pg-query-stream')
const JSONStream = require('JSONStream')

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