Skip to content

Commit e83e2c4

Browse files
committed
do not use try-catch in the example
1 parent 4f43a1d commit e83e2c4

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,10 @@ fastify.register(require('fastify-postgres'), {
106106
})
107107

108108
fastify.post('/user/:username', (req, reply) => {
109-
fastify.pg.transact(async client => {
110-
try {
111-
const id = await client.query('INSERT INTO users(username) VALUES($1) RETURNING id', [req.params.username])
112-
reply.send(id)
113-
} catch (err) {
114-
reply.send(err)
115-
}
109+
// will return a promise
110+
return fastify.pg.transact(async client => {
111+
// will resolve to an id, or reject with an error
112+
return await client.query('INSERT INTO users(username) VALUES($1) RETURNING id', [req.params.username])
116113
})
117114
})
118115

0 commit comments

Comments
 (0)