Skip to content

Commit f95c7c9

Browse files
author
Toni Sharpe
committed
WIP()
1 parent 1c78d07 commit f95c7c9

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

index.js

+7
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ function fastifyPostgres (fastify, options, next) {
102102
}
103103
}
104104

105+
if (!fastify.hasRequestDecorator('pg')) {
106+
fastify.decorateRequest('pg', null)
107+
fastify.addHook('onRequest', async (req, reply) => {
108+
req.pg = fastify.pg
109+
})
110+
}
111+
105112
next()
106113
}
107114

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "index.js",
66
"types": "index.d.ts",
77
"scripts": {
8+
"testonly": "tap -J test/*.test.js && npm run test:typescript",
89
"test": "standard && tap -J test/*.test.js && npm run test:typescript",
910
"test:typescript": "tsd",
1011
"test:report": "standard && tap -J --coverage-report=html test/*.test.js",

test/initialization.test.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ test('fastify.pg namespace should exist', (t) => {
192192
})
193193

194194
test('fastify.pg.test namespace should exist', (t) => {
195-
t.plan(6)
195+
t.plan(7)
196196

197197
const fastify = Fastify()
198198
t.teardown(() => fastify.close())
@@ -210,5 +210,23 @@ test('fastify.pg.test namespace should exist', (t) => {
210210
t.ok(fastify.pg.test.connect)
211211
t.ok(fastify.pg.test.pool)
212212
t.ok(fastify.pg.test.Client)
213+
t.ok(fastify.hasRequestDecorator('test'))
213214
})
214215
})
216+
217+
// test('fastify request should have the namespace', t => {
218+
// t.plan(2)
219+
// const fastify = Fastify()
220+
// t.teardown(() => fastify.close())
221+
222+
// fastify.register(fastifyPostgres, {
223+
// connectionString,
224+
// name: 'test'
225+
// })
226+
227+
// fastify.ready((err) => {
228+
// t.error(err)
229+
230+
// t.ok(fastify.hasRequestDecorator('test'))
231+
// })
232+
// })

0 commit comments

Comments
 (0)