Skip to content

Commit 779771a

Browse files
authored
Optionally disable fetching of array types. (#205)
* Optionally disable fetching of array types. * Document fetch_array_types
1 parent f900c58 commit 779771a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ const sql = postgres('postgres://username:password@host:port/database', {
7171
},
7272
target_session_attrs : null // Use 'read-write' with multiple hosts to
7373
// ensure only connecting to primary
74+
fetch_array_types : true // Disable automatically fetching array types
75+
// on initial connection.
7476
})
7577
```
7678

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

9799
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.
98100

101+
### Auto fetching of array types
102+
103+
When Postgres.js first connects to the database it automatically fetches array type information.
104+
105+
If you have revoked access to `pg_catalog` this feature will no longer work and will need to be disabled.
106+
107+
You can disable fetching array types by setting `fetch_array_types` to `false` when creating an instance.
108+
99109
### Environment Variables for Options
100110

101111
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:

lib/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function Postgres(a, b) {
6262

6363
let ready = false
6464
, ended = null
65-
, arrayTypesPromise
65+
, arrayTypesPromise = options.fetch_types ? null : Promise.resolve([])
6666
, slots = max
6767
, listener
6868

@@ -567,7 +567,8 @@ function parseOptions(a, b) {
567567
transform : Object.assign({}, o.transform),
568568
connection : Object.assign({ application_name: 'postgres.js' }, o.connection),
569569
target_session_attrs: o.target_session_attrs || url.query.target_session_attrs || env.PGTARGETSESSIONATTRS,
570-
debug : o.debug
570+
debug : o.debug,
571+
fetch_types : 'fetch_types' in o ? o.fetch_types : true
571572
},
572573
mergeUserTypes(o.types)
573574
)

0 commit comments

Comments
 (0)