12345678910111213141516171819202122232425262728293031323334353637383940 |
- // ███████╗██████╗ █████╗ ██╗ ██╗███╗ ██╗
- // ██╔════╝██╔══██╗██╔══██╗██║ ██║████╗ ██║
- // ███████╗██████╔╝███████║██║ █╗ ██║██╔██╗ ██║
- // ╚════██║██╔═══╝ ██╔══██║██║███╗██║██║╚██╗██║
- // ███████║██║ ██║ ██║╚███╔███╔╝██║ ╚████║
- // ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝ ╚═══╝
- //
- // ██████╗ ██████╗ ███╗ ██╗███╗ ██╗███████╗ ██████╗████████╗██╗ ██████╗ ███╗ ██╗
- // ██╔════╝██╔═══██╗████╗ ██║████╗ ██║██╔════╝██╔════╝╚══██╔══╝██║██╔═══██╗████╗ ██║
- // ██║ ██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██║ ██║ ██║██║ ██║██╔██╗ ██║
- // ██║ ██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██║ ██║ ██║██║ ██║██║╚██╗██║
- // ╚██████╗╚██████╔╝██║ ╚████║██║ ╚████║███████╗╚██████╗ ██║ ██║╚██████╔╝██║ ╚████║
- // ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝
- //
- // 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);
- }
- });
- };
|