Skip to content

Commit

Permalink
refactor: prefix unused params with underscores (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs authored Jan 6, 2025
1 parent 5bb4c9c commit 59178ee
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function fastifyPostgres (fastify, options, next) {
transact: transact.bind(pool)
}

fastify.addHook('onClose', (fastify, done) => pool.end(done))
fastify.addHook('onClose', (_fastify, done) => pool.end(done))

if (name) {
if (db[name]) {
Expand Down Expand Up @@ -135,7 +135,7 @@ function fastifyPostgres (fastify, options, next) {
return
}

const preHandler = async (req, reply) => {
const preHandler = async (req) => {
const client = await pool.connect()

if (name) {
Expand Down Expand Up @@ -164,7 +164,7 @@ function fastifyPostgres (fastify, options, next) {
await client.query('BEGIN')
}

const onError = (req, reply, error, done) => {
const onError = (req, _reply, _error, done) => {
req[transactionFailedSymbol] = true
extractRequestClient(req, transact).query('ROLLBACK', done)
}
Expand Down
4 changes: 2 additions & 2 deletions test/initialization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ test('Should not throw if registered within different scopes (with and without n
const fastify = Fastify()
t.after(() => fastify.close())

await fastify.register(function scopeOne (instance, opts, next) {
await fastify.register(function scopeOne (instance, _opts, next) {
instance.register(fastifyPostgres, {
connectionString
})

next()
})

await fastify.register(function scopeTwo (instance, opts, next) {
await fastify.register(function scopeTwo (instance, _opts, next) {
instance.register(fastifyPostgres, {
connectionString,
name: 'one'
Expand Down
34 changes: 17 additions & 17 deletions test/req-initialization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ test('When we use the fastify-postgres transaction route option', async t => {

await fastify.pg.query('DELETE FROM "users" WHERE TRUE')

fastify.get('/count-users', async (req, reply) => {
fastify.get('/count-users', async () => {
const result = await fastify.pg.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'pass-opt-in\'')

return result
})

fastify.get('/pass', { pg: { transact: true } }, async (req, reply) => {
fastify.get('/pass', { pg: { transact: true } }, async (req) => {
await req.pg.query('INSERT INTO users(username) VALUES($1) RETURNING id', ['pass-opt-in'])
await req.pg.query('INSERT INTO users(username) VALUES($1) RETURNING id', ['pass-opt-in'])
return 'complete'
Expand All @@ -51,13 +51,13 @@ test('When we use the fastify-postgres transaction route option', async t => {

await fastify.pg.test.query('DELETE FROM "users" WHERE TRUE')

fastify.get('/count-users', async (req, reply) => {
fastify.get('/count-users', async () => {
const result = await fastify.pg.test.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'pass-opt-in\'')

return result
})

fastify.get('/pass', { pg: { transact: 'test' } }, async (req, reply) => {
fastify.get('/pass', { pg: { transact: 'test' } }, async (req) => {
await req.pg.test.query('INSERT INTO users(username) VALUES($1) RETURNING id', ['pass-opt-in'])
await req.pg.test.query('INSERT INTO users(username) VALUES($1) RETURNING id', ['pass-opt-in'])

Expand All @@ -84,7 +84,7 @@ test('When we use the fastify-postgres transaction route option', async t => {

await fastify.pg.query('DELETE FROM "users" WHERE TRUE')

fastify.get('/count-users', async (req, reply) => {
fastify.get('/count-users', async (_req, reply) => {
const result = await fastify.pg.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'fail-opt-in\'')

reply.send(result)
Expand Down Expand Up @@ -119,7 +119,7 @@ test('When we use the fastify-postgres transaction route option', async t => {

await fastify.pg.test.query('DELETE FROM "users" WHERE TRUE')

fastify.get('/count-users', async (req, reply) => {
fastify.get('/count-users', async (_req, reply) => {
const result = await fastify.pg.test.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'fail-opt-in\'')

reply.send(result)
Expand Down Expand Up @@ -162,7 +162,7 @@ test('When we use the fastify-postgres transaction route option', async t => {
}
},
pg: { transact: true }
}, async (req, reply) => {
}, async () => {
t.assert.fail('should never execute the handler')
})

Expand All @@ -186,7 +186,7 @@ test('Should not add hooks with combinations of registration `options.name` and
await fastify.register(fastifyPostgres, {
connectionString
})
fastify.get('/', async (req, reply) => {
fastify.get('/', async (req) => {
t.assert.strictEqual(req.pg, null)
})
await fastify.inject({ url: '/' })
Expand All @@ -202,7 +202,7 @@ test('Should not add hooks with combinations of registration `options.name` and
connectionString,
name: 'test'
})
fastify.get('/', async (req, reply) => {
fastify.get('/', async (req) => {
t.assert.strictEqual(req.pg, null)
})

Expand All @@ -219,7 +219,7 @@ test('Should not add hooks with combinations of registration `options.name` and
connectionString,
name: 'test'
})
fastify.get('/', { pg: { transact: true } }, async (req, reply) => {
fastify.get('/', { pg: { transact: true } }, async (req) => {
t.assert.strictEqual(req.pg, null)
})

Expand All @@ -235,7 +235,7 @@ test('Should not add hooks with combinations of registration `options.name` and
await fastify.register(fastifyPostgres, {
connectionString
})
fastify.get('/', { pg: { transact: 'test' } }, async (req, reply) => {
fastify.get('/', { pg: { transact: 'test' } }, async (req) => {
t.assert.strictEqual(req.pg, null)
})

Expand All @@ -252,7 +252,7 @@ test('Should not add hooks with combinations of registration `options.name` and
connectionString,
name: 'test'
})
fastify.get('/', { pg: { transact: 'different' } }, async (req, reply) => {
fastify.get('/', { pg: { transact: 'different' } }, async (req) => {
t.assert.strictEqual(req.pg, null)
})

Expand All @@ -272,7 +272,7 @@ test('Should throw errors with incorrect combinations of registration `options.n
name
})

fastify.get('/', { pg: { transact: name } }, async (req, reply) => {})
fastify.get('/', { pg: { transact: name } }, async () => {})

const response = await fastify.inject({ url: '/' })
t.assert.deepStrictEqual(response.json(), {
Expand All @@ -292,10 +292,10 @@ test('Should throw errors with incorrect combinations of registration `options.n
connectionString,
name
})
fastify.addHook('onRequest', async (req, reply) => {
fastify.addHook('onRequest', async (req) => {
req.pg = { [name]: await fastify.pg[name].connect() }
})
fastify.get('/', { pg: { transact: name } }, async (req, reply) => {})
fastify.get('/', { pg: { transact: name } }, async () => {})

const response = await fastify.inject({ url: '/' })
t.assert.deepStrictEqual(response.json(), {
Expand All @@ -312,10 +312,10 @@ test('Should throw errors with incorrect combinations of registration `options.n
await fastify.register(fastifyPostgres, {
connectionString
})
fastify.addHook('onRequest', async (req, reply) => {
fastify.addHook('onRequest', async (req) => {
req.pg = await fastify.pg.connect()
})
fastify.get('/', { pg: { transact: true } }, async (req, reply) => {})
fastify.get('/', { pg: { transact: true } }, async () => {})

const response = await fastify.inject({ url: '/' })
t.assert.deepStrictEqual(response.json(), {
Expand Down
2 changes: 1 addition & 1 deletion test/transaction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ test('When fastify.pg root namespace is used:', async (t) => {
t.assert.ok(ready)

await t.assert.rejects(
async () => await fastify.pg.transact((client) => {}),
async () => await fastify.pg.transact(() => {}),
(err) => {
t.assert.ok(err)
t.assert.strictEqual(err.message, 'Boom')
Expand Down

0 comments on commit 59178ee

Please sign in to comment.