Skip to content

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

Merged
merged 7 commits into from
Oct 15, 2016

Conversation

kulshekhar
Copy link
Contributor

Resolves #2872

@facebook-github-bot
Copy link

@kulshekhar updated the pull request - view changes

@flovilmart
Copy link
Contributor

@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?

@kulshekhar
Copy link
Contributor Author

Sure.

Just so we're on the same page, would this mean moving the newly created getDatabaseOptionsFromURI and parseQueryParams functions into a separate PGConfigurationParser file?

@kulshekhar kulshekhar closed this Oct 15, 2016
@kulshekhar kulshekhar reopened this Oct 15, 2016
@flovilmart
Copy link
Contributor

Yep That would be nice, so that's properly tested on itself with different URLs and options, and properly covered.

@facebook-github-bot
Copy link

@kulshekhar updated the pull request - view changes

Copy link
Contributor

@flovilmart flovilmart left a 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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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
};
Copy link
Contributor

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

Copy link
Contributor Author

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')();
Copy link
Contributor

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

Copy link
Contributor

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 :)

Copy link
Contributor Author

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.

Copy link
Contributor

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 :)

Copy link
Contributor Author

@kulshekhar kulshekhar Oct 15, 2016

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;
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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

@facebook-github-bot
Copy link

@kulshekhar updated the pull request - view changes

@facebook-github-bot
Copy link

@kulshekhar updated the pull request - view changes

@facebook-github-bot
Copy link

@kulshekhar updated the pull request - view changes

@facebook-github-bot
Copy link

@kulshekhar updated the pull request - view changes

Copy link
Contributor

@flovilmart flovilmart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great! Thanks!

@flovilmart flovilmart merged commit de36d96 into parse-community:master Oct 15, 2016
@kulshekhar kulshekhar deleted the patch-postgres-options branch October 15, 2016 21:32
@lsxredrain
Copy link

nice fuction!

@lsxredrain
Copy link

name: 'error',
length: 108,
severity: 'ERROR',
code: '42703',
detail: undefined,
hint: undefined,
position: '33',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_relation.c',
line: '3090',
routine: 'errorMissingColumn' } error: column "password" does not exist
at Connection.parseE (/data/work/psql-parser/parse-server-example/node_modules/pg/lib/connection.js: 539:11)
at Connection.parseMessage (/data/work/psql-parser/parse-server-example/node_modules/pg/lib/connecti on.js:366:17)
at Socket. (/data/work/psql-parser/parse-server-example/node_modules/pg/lib/connection.js :105:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:543:20)
error: column "password" does not exist
at Connection.parseE (/data/work/psql-parser/parse-server-example/node_modules/pg/lib/connection.js: 539:11)
at Connection.parseMessage (/data/work/psql-parser/parse-server-example/node_modules/pg/lib/connecti on.js:366:17)
at Socket. (/data/work/psql-parser/parse-server-example/node_modules/pg/lib/connection.js :105:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:543:20)

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

Successfully merging this pull request may close these issues.

4 participants