-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
Code cleanup #110
Code cleanup #110
Conversation
Pull Request Test Coverage Report for Build 1265207839
💛 - Coveralls |
Pull Request Test Coverage Report for Build 1265335457Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
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.
Good work, this was much needed! I've left a small note.
@@ -102,19 +102,21 @@ function fastifyPostgres (fastify, options, next) { | |||
if (db[name]) { | |||
return next(new Error(`fastify-postgres '${name}' is a reserved keyword`)) | |||
} else if (!fastify.pg) { | |||
fastify.decorate('pg', {}) | |||
fastify.decorate('pg', Object.create(null)) |
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'm curious, what is the advantage of this approach?
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.
When we use Object.create(null)
we initialize a really empty object that inherit nothing.
Initializing the decorator with {}
instead is equivalent to Object.create(Object.prototype)
and we have an object that inherit the __proto__
property.
But in fact it can be considered to be just a minor optimization.
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.
lgtm
Hello,
I did a little refresh:
fastify.pg
andreq.pg
withObject.create(null)
instead of{}
, little if.. statements reorganization to fail fast and improve code readabilityAnd I updated this package dependencies too.
Checklist
npm run test
andnpm run benchmark
and/or benchmarksare includeddocumentation is changed or addedand the Code of conduct