Skip to content
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

Reorder the user, password, host, port and database appearances for uniformity. #3207

Merged
merged 1 commit into from
May 10, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: ci_db_test
POSTGRES_HOST_AUTH_METHOD: 'md5'
POSTGRES_DB: ci_db_test
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
Expand All @@ -50,8 +50,8 @@ jobs:
runs-on: ${{ matrix.os }}
env:
PGUSER: postgres
PGHOST: localhost
PGPASSWORD: postgres
PGHOST: localhost
PGDATABASE: ci_db_test
PGTESTNOSSL: 'true'
SCRAM_TEST_PGUSER: scram_test
Expand Down
6 changes: 3 additions & 3 deletions docs/pages/apis/client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type Config = {
user?: string, // default process.env.PGUSER || process.env.USER
password?: string or function, //default process.env.PGPASSWORD
host?: string, // default process.env.PGHOST
database?: string, // default process.env.PGDATABASE || user
port?: number, // default process.env.PGPORT
database?: string, // default process.env.PGDATABASE || user
connectionString?: string, // e.g. postgres://user:password@host:5432/database
ssl?: any, // passed directly to node.TLSSocket, supports all tls.connect options
types?: any, // custom type parsers
Expand All @@ -34,11 +34,11 @@ import pg from 'pg'
const { Client } = pg

const client = new Client({
user: 'database-user',
password: 'secretpassword!!',
host: 'my.database-server.com',
port: 5334,
database: 'database-name',
user: 'database-user',
password: 'secretpassword!!',
})
```

Expand Down
22 changes: 11 additions & 11 deletions docs/pages/features/connecting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ To run the above program and specify which database to connect to we can invoke

```sh
$ PGUSER=dbuser \
PGHOST=database.server.com \
PGPASSWORD=secretpassword \
PGDATABASE=mydb \
PGHOST=database.server.com \
PGPORT=3211 \
PGDATABASE=mydb \
node script.js
```

Expand All @@ -43,11 +43,11 @@ This allows us to write our programs without having to specify connection inform
The default values for the environment variables used are:

```
PGHOST=localhost
PGUSER=process.env.USER
PGDATABASE=process.env.USER
PGPASSWORD=null
PGHOST=localhost
PGPORT=5432
PGDATABASE=process.env.USER
```

## Programmatic
Expand All @@ -60,20 +60,20 @@ const { Pool, Client } = pg

const pool = new Pool({
user: 'dbuser',
host: 'database.server.com',
database: 'mydb',
password: 'secretpassword',
host: 'database.server.com',
port: 3211,
database: 'mydb',
})

console.log(await pool.query('SELECT NOW()'))

const client = new Client({
user: 'dbuser',
host: 'database.server.com',
database: 'mydb',
password: 'secretpassword',
host: 'database.server.com',
port: 3211,
database: 'mydb',
})

await client.connect()
Expand Down Expand Up @@ -106,11 +106,11 @@ const signer = new RDS.Signer()
const getPassword = () => signer.getAuthToken(signerOptions)

const pool = new Pool({
user: signerOptions.username,
password: getPassword,
host: signerOptions.hostname,
port: signerOptions.port,
user: signerOptions.username,
database: 'my-db',
password: getPassword,
})
```

Expand All @@ -122,9 +122,9 @@ Connections to unix sockets can also be made. This can be useful on distros like
import pg from 'pg'
const { Client } = pg
client = new Client({
host: '/cloudsql/myproject:zone:mydb',
user: 'username',
password: 'password',
host: '/cloudsql/myproject:zone:mydb',
database: 'database_name',
})
```
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 @@ -22,10 +22,10 @@ var config = parse('postgres://someuser:somepassword@somehost:381/somedatabase')

The resulting config contains a subset of the following properties:

* `host` - Postgres server hostname or, for UNIX domain sockets, the socket filename
* `port` - port on which to connect
* `user` - User with which to authenticate to the server
* `password` - Corresponding password
* `host` - Postgres server hostname or, for UNIX domain sockets, the socket filename
* `port` - port on which to connect
* `database` - Database name within the server
* `client_encoding` - string encoding the client will use
* `ssl`, either a boolean or an object with properties
Expand Down
4 changes: 2 additions & 2 deletions packages/pg-connection-string/test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ describe('parse', function () {
var sourceConfig = {
user: 'brian',
password: 'hello<ther>e',
port: 5432,
host: 'localhost',
port: 5432,
database: 'postgres',
}
var connectionString =
Expand All @@ -86,8 +86,8 @@ describe('parse', function () {
var sourceConfig = {
user: 'brian',
password: 'hello:pass:world',
port: 5432,
host: 'localhost',
port: 5432,
database: 'postgres',
}
var connectionString =
Expand Down
4 changes: 2 additions & 2 deletions packages/pg/script/create-test-tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ var people = [
]

var con = new pg.Client({
host: args.host,
port: args.port,
user: args.user,
password: args.password,
host: args.host,
port: args.port,
database: args.database,
})

Expand Down
10 changes: 5 additions & 5 deletions packages/pg/test/integration/client/configuration-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,26 @@ suite.test('default values are used in new clients', function () {
var client = new pg.Client()
assert.same(client, {
user: process.env.USER,
database: process.env.USER,
password: null,
port: 5432,
database: process.env.USER,
})
})

suite.test('modified values are passed to created clients', function () {
pg.defaults.user = 'boom'
pg.defaults.password = 'zap'
pg.defaults.database = 'pow'
pg.defaults.port = 1234
pg.defaults.host = 'blam'
pg.defaults.port = 1234
pg.defaults.database = 'pow'

var client = new Client()
assert.same(client, {
user: 'boom',
password: 'zap',
database: 'pow',
port: 1234,
host: 'blam',
port: 1234,
database: 'pow',
})
})

Expand Down
6 changes: 3 additions & 3 deletions packages/pg/test/unit/client/configuration-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,21 @@ test('initializing from a config string', function () {
test('when not including all values the environment variables are used', function () {
var envUserDefined = process.env['PGUSER'] !== undefined
var envPasswordDefined = process.env['PGPASSWORD'] !== undefined
var envDBDefined = process.env['PGDATABASE'] !== undefined
var envHostDefined = process.env['PGHOST'] !== undefined
var envPortDefined = process.env['PGPORT'] !== undefined
var envDBDefined = process.env['PGDATABASE'] !== undefined

var savedEnvUser = process.env['PGUSER']
var savedEnvPassword = process.env['PGPASSWORD']
var savedEnvDB = process.env['PGDATABASE']
var savedEnvHost = process.env['PGHOST']
var savedEnvPort = process.env['PGPORT']
var savedEnvDB = process.env['PGDATABASE']

process.env['PGUSER'] = 'utUser1'
process.env['PGPASSWORD'] = 'utPass1'
process.env['PGDATABASE'] = 'utDB1'
process.env['PGHOST'] = 'utHost1'
process.env['PGPORT'] = 5464
process.env['PGDATABASE'] = 'utDB1'

var client = new Client('postgres://host1')
assert.equal(client.user, process.env['PGUSER'])
Expand Down
16 changes: 8 additions & 8 deletions packages/pg/test/unit/connection-parameters/creation-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ suite.testAsync('builds simple string', async function () {
var config = {
user: 'brian',
password: 'xyz',
port: 888,
host: 'localhost',
port: 888,
database: 'bam',
}
var subject = new ConnectionParameters(config)
Expand All @@ -179,8 +179,8 @@ suite.testAsync('builds simple string', async function () {
var parts = constring.split(' ')
checkForPart(parts, "user='brian'")
checkForPart(parts, "password='xyz'")
checkForPart(parts, "port='888'")
checkForPart(parts, `hostaddr='${dnsHost}'`)
checkForPart(parts, "port='888'")
checkForPart(parts, "dbname='bam'")
resolve()
})
Expand All @@ -191,8 +191,8 @@ suite.test('builds dns string', async function () {
var config = {
user: 'brian',
password: 'asdf',
port: 5432,
host: 'localhost',
port: 5432,
}
var subject = new ConnectionParameters(config)
const dnsHost = await getDNSHost(config.host)
Expand All @@ -211,8 +211,8 @@ suite.test('error when dns fails', function () {
var config = {
user: 'brian',
password: 'asf',
port: 5432,
host: 'asdlfkjasldfkksfd#!$!!!!..com',
port: 5432,
}
var subject = new ConnectionParameters(config)
subject.getLibpqConnectionString(
Expand All @@ -227,8 +227,8 @@ suite.test('connecting to unix domain socket', function () {
var config = {
user: 'brian',
password: 'asf',
port: 5432,
host: '/tmp/',
port: 5432,
}
var subject = new ConnectionParameters(config)
subject.getLibpqConnectionString(
Expand All @@ -245,8 +245,8 @@ suite.test('config contains quotes and backslashes', function () {
var config = {
user: 'not\\brian',
password: "bad'chars",
port: 5432,
host: '/tmp/',
port: 5432,
}
var subject = new ConnectionParameters(config)
subject.getLibpqConnectionString(
Expand Down Expand Up @@ -277,8 +277,8 @@ suite.test('password contains < and/or > characters', function () {
var sourceConfig = {
user: 'brian',
password: 'hello<ther>e',
port: 5432,
host: 'localhost',
port: 5432,
database: 'postgres',
}
var connectionString =
Expand Down Expand Up @@ -333,8 +333,8 @@ suite.test('ssl is set on client', function () {
var sourceConfig = {
user: 'brian',
password: 'hello<ther>e',
port: 5432,
host: 'localhost',
port: 5432,
database: 'postgres',
ssl: {
sslmode: 'verify-ca',
Expand Down