added postConnectionQuery configuration #137
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I needed to set client-connection defaults, specifically 'SET extra_float_digits = 3;' to run before any other SQL query. This fixes an issue with double precision values being truncated (which I reported to node-postgres a while ago but got no response for - Issue 730).
As a generic way to set any of these parameters, I figured the ability to specify a SQL query that runs once whenever a new connection is opened would be best. So I added a postConnectionQuery configuration option, and modified the adapter.spawnConnection function. I toyed with the idea of specifying a JSON object or array of parameters instead, but figured directly specifying a SQL string would be easier and more flexible.
Also I'm not entirely sure how best to unit test this. As I couldn't see any tests on spawnConnection I have not made new ones.