Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
});
};
Support.Teardown = function teardown(tableName, cb) {
var manager = adapter.datastores[_.first(_.keys(adapter.datastores))].manager;
MySQL.getConnection({
manager: manager,
meta: Support.Config
}).exec(function getConnectionCb(err, report) {
if (err) {
return cb(err);
}
var query = 'DROP TABLE IF EXISTS `' + tableName + '`;';
MySQL.sendNativeQuery({
connection: report.connection,
nativeQuery: query
}).exec(function dropTableCb(err) {
if (err) {
return cb(err);
}
Support.Seed = function seed(tableName, cb) {
var manager = adapter.datastores[_.first(_.keys(adapter.datastores))].manager;
MySQL.getConnection({
manager: manager,
meta: Support.Config
}).exec(function getConnectionCb(err, report) {
if (err) {
return cb(err);
}
var query = [
'INSERT INTO `' + tableName + '` (`fieldA`, `fieldB`, `fieldC`, `fieldD`) ',
'values (\'foo\', \'bar\', null, null), (\'foo_2\', \'bAr_2\', $1, $2);'
].join('');
MySQL.sendNativeQuery({
connection: report.connection,
nativeQuery: query,
valuesToEscape: [new Buffer([1,2,3]), new Date('2001-06-15 12:00:00')]