Skip to content

Commit 8bf6407

Browse files
author
Toni Sharpe
committed
PR Comments
Resolves fastify#75
1 parent b9a417f commit 8bf6407

File tree

2 files changed

+10
-34
lines changed

2 files changed

+10
-34
lines changed

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function transact (fn, cb) {
5757
}
5858

5959
function extractRequestClient (req, transact) {
60-
if (transact.length) {
60+
if (typeof transact === 'string') {
6161
const requestClient = req.pg[transact]
6262
if (!requestClient) {
6363
throw new Error(`request client '${transact}' does not exist`)
@@ -158,7 +158,7 @@ function fastifyPostgres (fastify, options, next) {
158158
}
159159
}
160160

161-
extractRequestClient(req, transact).query('BEGIN')
161+
client.query('BEGIN')
162162
}
163163

164164
const onError = (req, reply, error, done) => {

test/req-initialization.test.js

+8-32
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ test('fastify postgress useTransaction route option', t => {
3131
reply.send('complete')
3232
})
3333

34-
await fastify.inject({
35-
method: 'GET',
36-
url: '/pass'
37-
})
34+
await fastify.inject({ url: '/pass' })
3835

3936
const response = await fastify.inject({
4037
method: 'GET',
@@ -67,10 +64,7 @@ test('fastify postgress useTransaction route option', t => {
6764
reply.send('complete')
6865
})
6966

70-
await fastify.inject({
71-
method: 'GET',
72-
url: '/pass'
73-
})
67+
await fastify.inject({ url: '/pass' })
7468

7569
const response = await fastify.inject({
7670
method: 'GET',
@@ -102,10 +96,7 @@ test('fastify postgress useTransaction route option', t => {
10296
reply.send('complete')
10397
})
10498

105-
await fastify.inject({
106-
method: 'GET',
107-
url: '/fail'
108-
})
99+
await fastify.inject({ url: '/fail' })
109100

110101
const response = await fastify.inject({
111102
method: 'GET',
@@ -133,10 +124,7 @@ test('combinations of registrationOptions.name and routeOptions.pg.transact that
133124
t.is(req.pg, null)
134125
})
135126

136-
fastify.inject({
137-
method: 'GET',
138-
url: '/'
139-
})
127+
fastify.inject({ url: '/' })
140128
})
141129
test('name set and transact not set', t => {
142130
t.plan(1)
@@ -153,10 +141,7 @@ test('combinations of registrationOptions.name and routeOptions.pg.transact that
153141
t.is(req.pg, null)
154142
})
155143

156-
fastify.inject({
157-
method: 'GET',
158-
url: '/'
159-
})
144+
fastify.inject({ url: '/' })
160145
})
161146
test('name set and transact set to true', t => {
162147
t.plan(1)
@@ -173,10 +158,7 @@ test('combinations of registrationOptions.name and routeOptions.pg.transact that
173158
t.is(req.pg, null)
174159
})
175160

176-
fastify.inject({
177-
method: 'GET',
178-
url: '/'
179-
})
161+
fastify.inject({ url: '/' })
180162
})
181163
test('name not set and transact set to string', t => {
182164
t.plan(1)
@@ -192,10 +174,7 @@ test('combinations of registrationOptions.name and routeOptions.pg.transact that
192174
t.is(req.pg, null)
193175
})
194176

195-
fastify.inject({
196-
method: 'GET',
197-
url: '/'
198-
})
177+
fastify.inject({ url: '/' })
199178
})
200179
test('name and transact set to different strings', t => {
201180
t.plan(1)
@@ -212,10 +191,7 @@ test('combinations of registrationOptions.name and routeOptions.pg.transact that
212191
t.is(req.pg, null)
213192
})
214193

215-
fastify.inject({
216-
method: 'GET',
217-
url: '/'
218-
})
194+
fastify.inject({ url: '/' })
219195
})
220196
t.end()
221197
})

0 commit comments

Comments
 (0)