-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Allow configuration options for Postgres #2873
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
Allow configuration options for Postgres #2873
Conversation
@kulshekhar updated the pull request - view changes |
@kulshekhar can you please add unit tests for the configuration parsing please? so we make sure this piece is correctly covered? Maybe refactor into a PGConfiguration parser (that would parse the options) and then keep the initialization 'outside' the configuration parser? |
Sure. Just so we're on the same page, would this mean moving the newly created |
Yep That would be nice, so that's properly tested on itself with different URLs and options, and properly covered. |
@kulshekhar updated the pull request - view changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nits here and there
function getDatabaseOptionsFromURI(uri) { | ||
const databaseOptions = {}; | ||
|
||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we surround with try/catch just to retrhow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to remove that. Will remove.
module.exports = { | ||
parseQueryParams: parseQueryParams, | ||
getDatabaseOptionsFromURI: getDatabaseOptionsFromURI | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add line at the end of the file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -0,0 +1,31 @@ | |||
const pgp = require('pg-promise')(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename file to PGClient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or PostgresClient for the sake of consistency :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't the client. It's just pg-promise being initialized. A call to pgp()
is what creates the client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So PostgresClient.createClient() still makes sense :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had misread your comment. I didn't realize you had asked for the file name to be changed (The code snippet made me think you'd asked for the variable name to be changed!)
I've updated the file name to PostgresClient
|
||
databaseOptions.client_encoding = queryParams.client_encoding; | ||
databaseOptions.application_name = queryParams.application_name; | ||
databaseOptions.fallback_application_name = queryParams.fallback_application_name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there additional options possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the only options mentioned here: https://github.com/vitaly-t/pg-promise/wiki/Connection-Syntax#configuration-object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok good, we'll keep an eye if new options arise from that module
@kulshekhar updated the pull request - view changes |
@kulshekhar updated the pull request - view changes |
@kulshekhar updated the pull request - view changes |
@kulshekhar updated the pull request - view changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great! Thanks!
nice fuction! |
name: 'error', |
Resolves #2872