Skip to content

Conversation

@temsa
Copy link
Contributor

@temsa temsa commented Oct 10, 2018

should fix #28

The test of the option is very simple and could probably be better

@cemremengu
Copy link
Contributor

While I think this does not belong to the scope of this plugin, it also enables extensibility.

@mcollina what do you think?

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

@cemremengu
Copy link
Contributor

cemremengu commented Oct 10, 2018

@mcollina this is semver-minor right? minor it is 😄

@temsa published, happy coding! :)

@cemremengu cemremengu merged commit 9445b88 into fastify:master Oct 10, 2018
@mcollina
Copy link
Member

mcollina commented Oct 10, 2018 via email


function fastifyPostgres (fastify, options, next) {
let pg = defaultPg
if (options.pg) {
Copy link
Member

Choose a reason for hiding this comment

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

While this seems legit to be able to pass pg into it, but I don't think there's a good use case.

At this line pg === defaultPg is actually true even if you pass the pg instance after patching it with pg-range, so not sure if there's any benefit in passing it altogether.

All pg-range does is patch the pg, it doesn't return a new/different object. So just requireing pg-range before fastify-postgres should do the trick.

Or am I missing something?

Copy link
Contributor

Choose a reason for hiding this comment

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

While I am not a continuous postgres user, it looks like require('pg') returns a factory and plugins are installed to that factory instance only so you need to pass that factory instance in?

@temsa do you mind trying the suggestion here to see it works?

Copy link
Member

Choose a reason for hiding this comment

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

I agree @cemremengu.

Also, the main reason I'm skeptical about this is that fastify-postgres is a dedicated library for pg. We do not support any other similar postgres module. Which is why I think allowing the user to pass a pg instance is not so intuitive because the user is free to pass any object and we have no control over it.

Copy link
Member

Choose a reason for hiding this comment

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

@mcollina what do you think about this?

Copy link
Member

Choose a reason for hiding this comment

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

This also enables mocking, which might be a good feature to support.

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.

Allow to override pg library

4 participants