Skip to content

Commit

Permalink
Optionally disable fetching of array types. (#205)
Browse files Browse the repository at this point in the history
* Optionally disable fetching of array types.

* Document fetch_array_types
  • Loading branch information
JAForbes authored Jul 30, 2021
1 parent f900c58 commit 779771a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ const sql = postgres('postgres://username:password@host:port/database', {
},
target_session_attrs : null // Use 'read-write' with multiple hosts to
// ensure only connecting to primary
fetch_array_types : true // Disable automatically fetching array types
// on initial connection.
})
```

Expand All @@ -96,6 +98,14 @@ Connecting to the specified hosts/ports will be tried in order, and on a success

If you specify `target_session_attrs: 'read-write'` or `PGTARGETSESSIONATTRS=read-write` Postgres.js will only connect to a writeable host allowing for zero down time failovers.

### Auto fetching of array types

When Postgres.js first connects to the database it automatically fetches array type information.

If you have revoked access to `pg_catalog` this feature will no longer work and will need to be disabled.

You can disable fetching array types by setting `fetch_array_types` to `false` when creating an instance.

### Environment Variables for Options

It is also possible to connect to the database without a connection string or any options. Postgres.js will fall back to the common environment variables used by `psql` as in the table below:
Expand Down
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function Postgres(a, b) {

let ready = false
, ended = null
, arrayTypesPromise
, arrayTypesPromise = options.fetch_types ? null : Promise.resolve([])
, slots = max
, listener

Expand Down Expand Up @@ -567,7 +567,8 @@ function parseOptions(a, b) {
transform : Object.assign({}, o.transform),
connection : Object.assign({ application_name: 'postgres.js' }, o.connection),
target_session_attrs: o.target_session_attrs || url.query.target_session_attrs || env.PGTARGETSESSIONATTRS,
debug : o.debug
debug : o.debug,
fetch_types : 'fetch_types' in o ? o.fetch_types : true
},
mergeUserTypes(o.types)
)
Expand Down

0 comments on commit 779771a

Please sign in to comment.