Add support for options
parameter in connection URLs
#547
Labels
accepted-proposal
The change proposal is accepted and contributions are welcome.
enhancement
released
Add support for
options
parameter in connection URLsDesired Behavior
options
added to a connection url get passed to the underlyingpg
library. For example:(I'm omitting proper url-encoding to make the example clear!)
Motivation
We use different database schemas for various environments, especially locally. For our main app, we generally use the
public
schema, but for running tests we use thetest
schema.A workaround has been setting the
PGOPTIONS=-c search_path=test
environment variable when running tests.However, now we need to connect to a different database that uses another convention for schemas. Specifically, the test schema name looks like
default$test
instead oftest
. It's not possible to set thePGOPTIONS
environment variable to two different settings, so ideally we could set options in the connection URL for each database that we connect to.Note that we are able to work around this by specifying a schema within our queries, for example:
but that syntax is a lot more verbose compared to simply writing
Thus there is no big rush to implement this, would just be nice to have.
Implementation
In the
parseDsn
utility, we could extract theoptions
like so (maybe with a more specific name thanoptions
):The underlying
pg
library already supports this parameter thanks to this PR from 2020: brianc/node-postgres#2216Beyond that, some types would need updating and the param needs to be passed around in the correct places, but I don't anticipate it being a difficult thing to support.
The text was updated successfully, but these errors were encountered: