Skip to content

Types: Add "pg" property to FastifyInstance #68

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 6 commits into from
Nov 9, 2020
Merged

Types: Add "pg" property to FastifyInstance #68

merged 6 commits into from
Nov 9, 2020

Conversation

voxpelli
Copy link
Contributor

@voxpelli voxpelli commented Nov 9, 2020

As recommended in the guide for creating TypeScript compatible Fastify plugins, properties that the Fastify instances are decorated with should also in the types get added to those instances: https://www.fastify.io/docs/latest/TypeScript/#creating-a-typescript-fastify-plugin

This change follows up on #63 by adding that.

Checklist

As recommended in the guide for creating TypeScript compatible Fastify plugins, properties that the Fastify instances are decorated with should also in the types get added to those instances: https://www.fastify.io/docs/latest/TypeScript/#creating-a-typescript-fastify-plugin

This change follows up on #63 by adding that.
@voxpelli
Copy link
Contributor Author

voxpelli commented Nov 9, 2020

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.

Can you please add a unit test?

Copy link
Member

@fox1t fox1t left a comment

Choose a reason for hiding this comment

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

Nice catch!

LGTM after adding tests.

@voxpelli
Copy link
Contributor Author

voxpelli commented Nov 9, 2020

This became more complex.

For some odd reason this module has an undocumented, yet tested and verified, capability that allows it to expose fastify.pg as either a PostgresDb directly or as a an object keyed with named database connections, each one containing a PostgresDb.

The latter is achieved by adding the module multiple times, each time adding a name.

So:

I changed course here a bit. Adding documentation for that property + tests that ensures that one always take one or the other approach.

Also clarified the intention that one should manually be adding the pg property to the FastifyInstance type.

Up next, in another PR, I would want to do a breaking change:

Have fastify.pg always be for a single db.
Have fastify.pgMulti (or similar name) always be for multiple db:s.

That way it's actually possible to expose types for both out of the box, without any users having to manually add the correct one for them.

How does that sound? Can we merge this PR as it is with the documentation and test improvements? And I'll open a new one that takes care of a possible breaking change.

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

@mcollina mcollina merged commit 5d49ea5 into fastify:master Nov 9, 2020
@voxpelli voxpelli deleted the patch-1 branch November 9, 2020 19:28
mcollina pushed a commit that referenced this pull request Nov 13, 2020
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.

3 participants