Skip to content
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

Question: how to properly set datestyle on pooled connections #1393

Closed
bydga opened this issue Aug 1, 2017 · 3 comments
Closed

Question: how to properly set datestyle on pooled connections #1393

bydga opened this issue Aug 1, 2017 · 3 comments

Comments

@bydga
Copy link

bydga commented Aug 1, 2017

When using the pool.connect & client.release approach, I'm setting the set datestyle = iso mdy as a first query to have my date-types parsed properly.

However, how to do it with the pool.query call? Since the connection returned is random - and might be an existing one recently returned to the pool as well as a newly established one..

Im not sure, if setting pg.types.setTypeParser for all the date/datetime/timestamp with/without timezone is a way I want to go..

Suggestions? :)

@charmander
Copy link
Collaborator

You can create a client type for use with the pool providing custom startup configuration:

const pool = new pg.Pool({
    Client: class extends pg.Client {
        getStartupConf() {
            return Object.assign(super.getStartupConf(), {
                DateStyle: 'ISO,MDY',
            });
        }
    },});

It might be nice to have an option along these lines, though:

class pool = new pg.Pool({
    connectionOptions: {
        DateStyle: 'ISO,MDY',
    },});

@bydga
Copy link
Author

bydga commented Aug 1, 2017

hm, i've solved it by doing

pool.on "connect", (client) ->
    client.query "SET DATESTYLE = iso, mdy"

but your solution looks better :)

@brianc
Copy link
Owner

brianc commented Aug 7, 2017

I added this to the documentation

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

No branches or pull requests

3 participants