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
docs: add database guide page #3704
Conversation
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.
That's very good! Thanks.
Could you add a note to show that users can also create their plugins for any database library, for instance, knex
?
Great! This closes #3562 |
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 think this is a good start, but as a reader I would expect more "guide" than "just install this plugin". In particular, it seems like the case of a missing database plugin could be expanded to a full section that details how one would write a new database plugin. It would cover things like how to decorate the instance properly and how to close the database connection when the Fastify server is stopped.
docs/Guides/Database.md
Outdated
connectionString: 'mysql://root@localhost/mysql' | ||
}) | ||
|
||
fastify.get('/user/:id', (req, reply) => { |
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.
Please do not use arrow functions for route handlers:
fastify.get('/user/:id', (req, reply) => { | |
fastify.get('/user/:id', function (req, reply) { |
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! Could you cover migrations too? I would recommend postgrator.
docs/Guides/Database.md
Outdated
function knexPlugin(fastify, options, done) { | ||
if(!fastify.knex) { | ||
fastify.decorate('knex', knex(options)) | ||
} | ||
|
||
done() | ||
} |
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 will keep a connection open and prevent fastify.close
from working.
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.
Fixed, please take a look.
docs/Guides/Database.md
Outdated
|
||
Fastify's ecosystem provides a handful of | ||
plugins for connecting to various database engines. | ||
This guide covers engines which have Fastify |
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 guide covers engines which have Fastify | |
This guide covers engines that have Fastify |
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.
Fixed, please check.
docs/Guides/Database.md
Outdated
This guide covers engines which have Fastify | ||
plugins maintained within the Fastify organization. | ||
|
||
> If a plugin for your database of choice doesn't exist |
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.
> If a plugin for your database of choice doesn't exist | |
> If a plugin for your database of choice does not exist |
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.
Fixed, please check.
Good example of Postgrator being used would be covidgreen/covid-green-backend-api; ended up adopting it myself after seeing it here. |
docs/Guides/Database.md
Outdated
### Writing a plugin for a database engine | ||
|
||
In this example, we will create a basic Fastify MySQL plugin | ||
from scratch (it's stripped example, please use the official plugin in production). |
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.
from scratch (it's stripped example, please use the official plugin in production). | |
from scratch (it is a stripped-down example, please use the official plugin in production). |
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.
Technically, the informal language is okay as this is a "guide".
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
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.
Co-authored-by: Frazer Smith <frazer.dev@outlook.com>
Adds a guide's page for database integration. It focuses on officially maintained plugins (MySQL, Postgres, MongoDB, Redis, LevelDB).
Checklist
npm run test
andnpm run benchmark
and the Code of conduct