diff --git a/README.md b/README.md index 4ce67db9..de306639 100644 --- a/README.md +++ b/README.md @@ -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. }) ``` @@ -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: diff --git a/lib/index.js b/lib/index.js index c9530f0c..a48174b7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -62,7 +62,7 @@ function Postgres(a, b) { let ready = false , ended = null - , arrayTypesPromise + , arrayTypesPromise = options.fetch_types ? null : Promise.resolve([]) , slots = max , listener @@ -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) )