hapi-plugin-mysql
Advanced tools
Comparing version 7.2.6 to 7.2.7
@@ -18,4 +18,2 @@ 'use strict'; | ||
request.app.connection = connection; | ||
// Since commit/rollback/beginTransaction uses the .query it will auto promisify them | ||
request.app.connection.query = Util.promisify(connection.query); | ||
@@ -34,11 +32,2 @@ return h.continue; | ||
if (!callback) { | ||
const connection = await internals.getConnection(); | ||
// Since commit/rollback/beginTransaction uses the .query it will auto promisify them | ||
connection.query = Util.promisify(connection.query); | ||
return connection; | ||
} | ||
let connection; | ||
@@ -49,6 +38,14 @@ try { | ||
catch (err) { | ||
return callback(err); | ||
if (callback) { | ||
return callback(err); | ||
} | ||
throw err; | ||
} | ||
return callback(null, connection); | ||
if (callback) { | ||
return callback(null, connection); | ||
} | ||
return connection; | ||
}; | ||
@@ -68,2 +65,7 @@ | ||
// Since commit/rollback/beginTransaction uses the .query it will auto promisify them | ||
// Node's `util.promisify` adds a symbol with the promisified version of the function | ||
// After promisifying `connection.query` also still works with callbacks | ||
connection.query = Util.promisify(connection.query); | ||
return resolve(connection); | ||
@@ -161,5 +163,3 @@ }); | ||
server.log(['hapi-plugin-mysql', 'database'], 'Connection to the database successful'); | ||
} | ||
}; |
{ | ||
"name": "hapi-plugin-mysql", | ||
"version": "7.2.6", | ||
"version": "7.2.7", | ||
"description": "Hapi plugin for MySQL", | ||
@@ -9,3 +9,3 @@ "main": "lib/index.js", | ||
"lint": "eslint --fix .", | ||
"test": "lab -a @hapi/code -vL --lint-fix -t 96" | ||
"test": "lab -m 5000 -a @hapi/code -vL --lint-fix -t 95" | ||
}, | ||
@@ -12,0 +12,0 @@ "repository": { |
@@ -456,3 +456,23 @@ 'use strict'; | ||
}); | ||
it('Promisified `.query` usage with callbacks', async () => { | ||
const MySQLPlugin = require('..'); | ||
await MySQLPlugin.init(internals.dbOptions); | ||
const connection = await MySQLPlugin.getConnection(); | ||
return new Promise((resolve) => { | ||
return connection.query('INSERT INTO test SET id = null', (err, results) => { | ||
expect(err, 'error').to.not.exist(); | ||
expect(results.insertId, 'insert Id').to.exist(); | ||
return resolve(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
23577
12
455
1