From d5a33354975b61f755bc23c0064a729581cc50ef Mon Sep 17 00:00:00 2001 From: Michael Marti <35479130+mmarti@users.noreply.github.com> Date: Mon, 7 Nov 2022 20:55:29 -0800 Subject: [PATCH 1/2] fix example using db decorator on fastify instance I believe the current docs are a typo/broken example, unless that's an undocumented syntax. This change adds an example for both returning the value since we're using async/await, along with an example for still using `reply.send()` and then `await`ing `reply`. --- docs/Reference/Decorators.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/Reference/Decorators.md b/docs/Reference/Decorators.md index b2bf0a9985..0895d4ee36 100644 --- a/docs/Reference/Decorators.md +++ b/docs/Reference/Decorators.md @@ -107,7 +107,13 @@ route [route](./Routes.md) handlers: fastify.decorate('db', new DbConnection()) fastify.get('/', async function (request, reply) { - reply({hello: await this.db.query('world')}) + // using return + return { hello: await this.db.query('world') }; + + // or + // using reply.send() + reply.send({ hello: await this.db.query('world') }); + await reply; }) ``` From 0a0724777b2845f490c75c0ae7329781d168fe5c Mon Sep 17 00:00:00 2001 From: Michael Marti <35479130+mmarti@users.noreply.github.com> Date: Mon, 7 Nov 2022 21:00:08 -0800 Subject: [PATCH 2/2] remove semicolons --- docs/Reference/Decorators.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/Reference/Decorators.md b/docs/Reference/Decorators.md index 0895d4ee36..fe413c139b 100644 --- a/docs/Reference/Decorators.md +++ b/docs/Reference/Decorators.md @@ -108,12 +108,12 @@ fastify.decorate('db', new DbConnection()) fastify.get('/', async function (request, reply) { // using return - return { hello: await this.db.query('world') }; + return { hello: await this.db.query('world') } // or // using reply.send() - reply.send({ hello: await this.db.query('world') }); - await reply; + reply.send({ hello: await this.db.query('world') }) + await reply }) ```