File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -106,13 +106,14 @@ fastify.register(require('fastify-postgres'), {
106
106
})
107
107
108
108
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, fastify will send the result automatically
110
+ return fastify .pg .transact (async client => {
111
+ // will resolve to an id, or reject with an error
112
+ const id = await client .query (' INSERT INTO users(username) VALUES($1) RETURNING id' , [req .params .username ])
113
+
114
+ // potentially do something with id
115
+
116
+ return id
116
117
})
117
118
})
118
119
You can’t perform that action at this time.
0 commit comments