Skip to content

Commit 7a4ef4b

Browse files
authored
Document environment variables (porsager#48)
* Document environment variables * Add code example and heading, clarify
1 parent 9dfdd88 commit 7a4ef4b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

README.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ await sql`
4343
You can use either a `postgres://` url connection string or the options to define your database connection properties. Options in the object will override any present in the url.
4444

4545
```js
46-
4746
const sql = postgres('postgres://username:password@host:port/database', {
4847
host : '', // Postgres ip address or domain name
4948
port : 5432, // Postgres server port
@@ -68,11 +67,26 @@ const sql = postgres('postgres://username:password@host:port/database', {
6867
... // Other connection parameters
6968
}
7069
})
71-
7270
```
7371

7472
More info for the `ssl` option can be found in the [Node.js docs for tls connect options](https://nodejs.org/dist/latest-v10.x/docs/api/tls.html#tls_new_tls_tlssocket_socket_options)
7573

74+
### Environment Variables for Options
75+
76+
It is also possible to connect to the database without a connection string or options, which will read the options from the environment variables in the table below:
77+
78+
```js
79+
const sql = postgres()
80+
```
81+
82+
| Option | Environment Variables |
83+
| ---------- | ------------------------ |
84+
| `host` | `PGHOST` |
85+
| `port` | `PGPORT` |
86+
| `database` | `PGDATABASE` |
87+
| `username` | `PGUSERNAME` or `PGUSER` |
88+
| `password` | `PGPASSWORD` |
89+
7690
## Query ```sql` ` -> Promise```
7791

7892
A query will always return a `Promise` which resolves to a results array `[...]{ rows, command }`. Destructuring is great to immediately access the first element.

0 commit comments

Comments
 (0)