release-connection.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // ██████╗ ███████╗██╗ ███████╗ █████╗ ███████╗███████╗
  2. // ██╔══██╗██╔════╝██║ ██╔════╝██╔══██╗██╔════╝██╔════╝
  3. // ██████╔╝█████╗ ██║ █████╗ ███████║███████╗█████╗
  4. // ██╔══██╗██╔══╝ ██║ ██╔══╝ ██╔══██║╚════██║██╔══╝
  5. // ██║ ██║███████╗███████╗███████╗██║ ██║███████║███████╗
  6. // ╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝
  7. //
  8. // ██████╗ ██████╗ ███╗ ██╗███╗ ██╗███████╗ ██████╗████████╗██╗ ██████╗ ███╗ ██╗
  9. // ██╔════╝██╔═══██╗████╗ ██║████╗ ██║██╔════╝██╔════╝╚══██╔══╝██║██╔═══██╗████╗ ██║
  10. // ██║ ██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██║ ██║ ██║██║ ██║██╔██╗ ██║
  11. // ██║ ██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██║ ██║ ██║██║ ██║██║╚██╗██║
  12. // ╚██████╗╚██████╔╝██║ ╚████║██║ ╚████║███████╗╚██████╗ ██║ ██║╚██████╔╝██║ ╚████║
  13. // ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝
  14. //
  15. // Release an open database connection.
  16. var MySQL = require('machinepack-mysql');
  17. module.exports = function releaseConnection(connection, leased, cb) {
  18. // If this connection was leased outside of the Adapter, don't release it.
  19. if (leased) {
  20. return setImmediate(function ensureAsync() {
  21. return cb();
  22. });
  23. }
  24. MySQL.releaseConnection({
  25. connection: connection
  26. }).switch({
  27. error: function error(err) {
  28. return cb(new Error('There was an error releasing the connection back into the pool.' + err.stack));
  29. },
  30. badConnection: function badConnection() {
  31. return cb(new Error('Bad connection when trying to release an active connection.'));
  32. },
  33. success: function success() {
  34. return cb();
  35. }
  36. });
  37. };