Skip to content

Commit 408bebd

Browse files
authored
Fix import syntax for commonJS in documentation (#3191)
1 parent 68171dd commit 408bebd

File tree

14 files changed

+78
-44
lines changed

14 files changed

+78
-44
lines changed

docs/pages/announcements.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ [email protected]
116116
To demonstrate the issue & see if you are vunerable execute the following in node:
117117

118118
```js
119-
import { Client } from 'pg'
119+
import pg from 'pg'
120+
const { Client } = pg
120121
const client = new Client()
121122
client.connect()
122123

docs/pages/apis/client.mdx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ type Config = {
2929
example to create a client with specific connection information:
3030
3131
```js
32-
import { Client } from 'pg'
32+
import pg from 'pg'
33+
const { Client } = pg
3334

3435
const client = new Client({
3536
host: 'my.database-server.com',
@@ -43,7 +44,8 @@ const client = new Client({
4344
## client.connect
4445

4546
```js
46-
import { Client } from 'pg'
47+
import pg from 'pg'
48+
const { Client } = pg
4749
const client = new Client()
4850

4951
await client.connect()
@@ -82,7 +84,8 @@ client.query(text: string, values?: any[]) => Promise<Result>
8284
**Plain text query**
8385

8486
```js
85-
import { Client } from 'pg'
87+
import pg from 'pg'
88+
const { Client } = pg
8689
const client = new Client()
8790

8891
await client.connect()
@@ -96,7 +99,8 @@ await client.end()
9699
**Parameterized query**
97100

98101
```js
99-
import { Client } from 'pg'
102+
import pg from 'pg'
103+
const { Client } = pg
100104
const client = new Client()
101105

102106
await client.connect()
@@ -134,7 +138,8 @@ await client.end()
134138
If you pass an object to `client.query` and the object has a `.submit` function on it, the client will pass it's PostgreSQL server connection to the object and delegate query dispatching to the supplied object. This is an advanced feature mostly intended for library authors. It is incidentally also currently how the callback and promise based queries above are handled internally, but this is subject to change. It is also how [pg-cursor](https://github.com/brianc/node-pg-cursor) and [pg-query-stream](https://github.com/brianc/node-pg-query-stream) work.
135139

136140
```js
137-
import { Query } from 'pg'
141+
import pg from 'pg'
142+
const { Query } = pg
138143
const query = new Query('select $1::text as name', ['brianc'])
139144

140145
const result = client.query(query)

docs/pages/apis/cursor.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ $ npm install pg pg-cursor
1818
Instantiates a new Cursor. A cursor is an instance of `Submittable` and should be passed directly to the `client.query` method.
1919

2020
```js
21-
import { Pool } from 'pg'
21+
import pg from 'pg'
22+
const { Pool } = pg
2223
import Cursor from 'pg-cursor'
2324

2425
const pool = new Pool()
@@ -57,7 +58,8 @@ If the cursor has read to the end of the result sets all subsequent calls to cur
5758
Here is an example of reading to the end of a cursor:
5859

5960
```js
60-
import { Pool } from 'pg'
61+
import pg from 'pg'
62+
const { Pool } = pg
6163
import Cursor from 'pg-cursor'
6264

6365
const pool = new Pool()

docs/pages/apis/pool.mdx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ type Config = {
4848
example to create a new pool with configuration:
4949
5050
```js
51-
import { Pool } from 'pg'
51+
import pg from 'pg'
52+
const { Pool } = pg
5253

5354
const pool = new Pool({
5455
host: 'localhost',
@@ -68,7 +69,8 @@ pool.query(text: string, values?: any[]) => Promise<pg.Result>
6869
```
6970

7071
```js
71-
import { Pool } from 'pg'
72+
import pg from 'pg'
73+
const { Pool } = pg
7274

7375
const pool = new Pool()
7476

@@ -100,7 +102,8 @@ Acquires a client from the pool.
100102
- If the pool is 'full' and all clients are currently checked out will wait in a FIFO queue until a client becomes available by it being released back to the pool.
101103

102104
```js
103-
import { Pool } from 'pg'
105+
import pg from 'pg'
106+
const { Pool } = pg
104107

105108
const pool = new Pool()
106109

@@ -118,7 +121,8 @@ Client instances returned from `pool.connect` will have a `release` method which
118121
The `release` method on an acquired client returns it back to the pool. If you pass a truthy value in the `destroy` parameter, instead of releasing the client to the pool, the pool will be instructed to disconnect and destroy this client, leaving a space within itself for a new client.
119122

120123
```js
121-
import { Pool } from 'pg'
124+
import pg from 'pg'
125+
const { Pool } = pg
122126

123127
const pool = new Pool()
124128

@@ -130,7 +134,8 @@ client.release()
130134
```
131135

132136
```js
133-
import { Pool } from 'pg'
137+
import pg from 'pg'
138+
const { Pool } = pg
134139

135140
const pool = new Pool()
136141
assert(pool.totalCount === 0)
@@ -163,7 +168,8 @@ Calling `pool.end` will drain the pool of all active clients, disconnect them, a
163168

164169
```js
165170
// again both promises and callbacks are supported:
166-
import { Pool } from 'pg'
171+
import pg from 'pg'
172+
const { Pool } = pg
167173

168174
const pool = new Pool()
169175

docs/pages/apis/result.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ Every result will have a rows array. If no rows are returned the array will be e
1818
Every result will have a fields array. This array contains the `name` and `dataTypeID` of each field in the result. These fields are ordered in the same order as the columns if you are using `arrayMode` for the query:
1919

2020
```js
21-
import { Pool } from 'pg'
21+
import pg from 'pg'
22+
const { Pool } = pg
2223

2324
const pool = new Pool()
2425

docs/pages/features/connecting.mdx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ title: Connecting
77
node-postgres uses the same [environment variables](https://www.postgresql.org/docs/9.1/static/libpq-envars.html) as libpq and psql to connect to a PostgreSQL server. Both individual clients & pools will use these environment variables. Here's a tiny program connecting node.js to the PostgreSQL server:
88

99
```js
10-
import { Pool, Client } from 'pg'
10+
import pg from 'pg'
11+
const { Pool, Client } = pg
1112

1213
// pools will use environment variables
1314
// for connection information
@@ -54,7 +55,8 @@ PGPORT=5432
5455
node-postgres also supports configuring a pool or client programmatically with connection information. Here's our same script from above modified to use programmatic (hard-coded in this case) values. This can be useful if your application already has a way to manage config values or you don't want to use environment variables.
5556

5657
```js
57-
import { Pool, Client } from 'pg'
58+
import pg from 'pg'
59+
const { Pool, Client } = pg
5860

5961
const pool = new Pool({
6062
user: 'dbuser',
@@ -84,7 +86,8 @@ await client.end()
8486
Many cloud providers include alternative methods for connecting to database instances using short-lived authentication tokens. node-postgres supports dynamic passwords via a callback function, either synchronous or asynchronous. The callback function must resolve to a string.
8587

8688
```js
87-
import { Pool } from 'pg'
89+
import pg from 'pg'
90+
const { Pool } = pg
8891
import { RDS } from 'aws-sdk'
8992

9093
const signerOptions = {
@@ -116,7 +119,8 @@ const pool = new Pool({
116119
Connections to unix sockets can also be made. This can be useful on distros like Ubuntu, where authentication is managed via the socket connection instead of a password.
117120

118121
```js
119-
import { Client } from 'pg'
122+
import pg from 'pg'
123+
const { Client } = pg
120124
client = new Client({
121125
host: '/cloudsql/myproject:zone:mydb',
122126
user: 'username',
@@ -130,7 +134,8 @@ client = new Client({
130134
You can initialize both a pool and a client with a connection string URI as well. This is common in environments like Heroku where the database connection string is supplied to your application dyno through an environment variable. Connection string parsing brought to you by [pg-connection-string](https://github.com/brianc/node-postgres/tree/master/packages/pg-connection-string).
131135

132136
```js
133-
import { Pool, Client } from 'pg'
137+
import pg from 'pg'
138+
const { Pool, Client } = pg
134139
const connectionString = 'postgresql://dbuser:[email protected]:3211/mydb'
135140

136141
const pool = new Pool({

docs/pages/features/native.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ $ npm install pg pg-native
1515
Once `pg-native` is installed instead of requiring a `Client` or `Pool` constructor from `pg` you do the following:
1616

1717
```js
18-
import { native } from 'pg'
18+
import pg from 'pg'
19+
const { native } = pg
1920
const { Client, Pool } = native
2021
```
2122

docs/pages/features/pooling.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ The client pool allows you to have a reusable pool of clients you can check out,
2828
### Checkout, use, and return
2929

3030
```js
31-
import { Pool } from 'pg'
31+
import pg from 'pg'
32+
const { Pool } = pg
3233

3334
const pool = new Pool()
3435

@@ -60,7 +61,8 @@ client.release()
6061
If you don't need a transaction or you just need to run a single query, the pool has a convenience method to run a query on any available client in the pool. This is the preferred way to query with node-postgres if you can as it removes the risk of leaking a client.
6162

6263
```js
63-
import { Pool } from 'pg'
64+
import pg from 'pg'
65+
const { Pool } = pg
6466

6567
const pool = new Pool()
6668

@@ -73,7 +75,8 @@ console.log('user:', res.rows[0])
7375
To shut down a pool call `pool.end()` on the pool. This will wait for all checked-out clients to be returned and then shut down all the clients and the pool timers.
7476

7577
```js
76-
import { Pool } from 'pg'
78+
import pg from 'pg'
79+
const { Pool } = pg
7780
const pool = new Pool()
7881

7982
console.log('starting async query')

docs/pages/features/ssl.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ const config = {
2222
},
2323
}
2424

25-
import { Client, Pool } from 'pg'
25+
import pg from 'pg'
26+
const { Client, Pool } = pg
2627

2728
const client = new Client(config)
2829
await client.connect()

docs/pages/features/transactions.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ To execute a transaction with node-postgres you simply execute `BEGIN / COMMIT /
1616
## Examples
1717

1818
```js
19-
import { Pool } from 'pg'
19+
import pg from 'pg'
20+
const { Pool } = pg
2021
const pool = new Pool()
2122

2223
const client = await pool.connect()
@@ -36,4 +37,4 @@ try {
3637
} finally {
3738
client.release()
3839
}
39-
```
40+
```

0 commit comments

Comments
 (0)