// ███████╗██████╗ █████╗ ██╗ ██╗███╗ ██╗ // ██╔════╝██╔══██╗██╔══██╗██║ ██║████╗ ██║ // ███████╗██████╔╝███████║██║ █╗ ██║██╔██╗ ██║ // ╚════██║██╔═══╝ ██╔══██║██║███╗██║██║╚██╗██║ // ███████║██║ ██║ ██║╚███╔███╔╝██║ ╚████║ // ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝ ╚═══╝ // // ██████╗ ██████╗ ███╗ ██╗███╗ ██╗███████╗ ██████╗████████╗██╗ ██████╗ ███╗ ██╗ // ██╔════╝██╔═══██╗████╗ ██║████╗ ██║██╔════╝██╔════╝╚══██╔══╝██║██╔═══██╗████╗ ██║ // ██║ ██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██║ ██║ ██║██║ ██║██╔██╗ ██║ // ██║ ██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██║ ██║ ██║██║ ██║██║╚██╗██║ // ╚██████╗╚██████╔╝██║ ╚████║██║ ╚████║███████╗╚██████╗ ██║ ██║╚██████╔╝██║ ╚████║ // ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ // // Instantiate a new connection from the connection manager. var MySQL = require('machinepack-mysql'); module.exports = function spawnConnection(datastore, cb) { // Validate datastore if (!datastore || !datastore.manager || !datastore.config) { return cb(new Error('Spawn Connection requires a valid datastore.')); } MySQL.getConnection({ manager: datastore.manager, meta: datastore.config }) .switch({ error: function error(err) { return cb(err); }, failed: function failedToConnect(err) { return cb(err); }, success: function success(connection) { return cb(null, connection.connection); } }); };