Skip to content

added postConnectionQuery configuration #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

added postConnectionQuery configuration #137

wants to merge 1 commit into from

Conversation

yacoobk
Copy link

@yacoobk yacoobk commented Mar 13, 2015

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.

…ults when opening a connection to postgres
@tjwebb
Copy link
Contributor

tjwebb commented Mar 28, 2015

You could do this in a sails hook as well, by listening for hooks:orm:loaded. Or if you're just using waterline, you could run this query in the waterline.initialize callback.

@yacoobk
Copy link
Author

yacoobk commented Mar 28, 2015

Thanks for your suggestion. The client-connection default must be run on every opened database connection once before any regular sails model query is issued.

By default 10 connections to the postgres database are opened by node-postgres, and it manages connection pooling automatically. I was under the impression using the sails hook or waterline.initialise would issue the query only once, not on every postgres connection. Would that be the case? Also what would happen if a db connection is dropped and a new one established - how would the hooks or waterline approach you have suggested behave?

@particlebanana
Copy link
Contributor

I'd rather see this supported at the node-pg level. This could come in handy when we get transactions added to set what the default level is but we can take a pass then. I would pressure the node-pg team if this is really an issue with the driver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants