Skip to content

Commit

Permalink
docs: fix example using db decorator on fastify instance (#4406)
Browse files Browse the repository at this point in the history
* 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`.

* remove semicolons
  • Loading branch information
Michael Marti committed Nov 8, 2022
1 parent 675b00d commit ea58581
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/Reference/Decorators.md
Expand Up @@ -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
})
```

Expand Down

0 comments on commit ea58581

Please sign in to comment.