Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var mysql = require('mysql');
var assert = require('assert');
var lib_dir = 'lib';
if (process.env.EASY_MYSQL_JSCOV) {
lib_dir = 'lib-cov';
}
var EasyMySQL = require('../' + lib_dir + '/easy_mysql');
var EasyClient = require('../' + lib_dir + '/easy_client');
var easy_pool = require('../' + lib_dir + '/easy_pool');
var conn_method = 'createConnection';
if (mysql.hasOwnProperty('createClient')) {
conn_method = 'createClient';
}
function clone(object) {
var ret = {};
Object.keys(object).forEach(function (val) {
ret[val] = object[val];
});
return ret;
}
function random_string() {
return 'str' + Math.floor(Math.random() * 10000000000);
}
try {
EasyClient.fetch = function (settings, cb) {
if (settings.pool) {
get_client_from_pool(settings.pool, cb);
} else if (settings.use_easy_pool) {
var pool = easy_pool.fetch(settings);
get_client_from_pool(pool, cb);
} else {
var client;
if (mysql.hasOwnProperty('createConnection')) {
client = mysql.createConnection(settings);
} else if (mysql.hasOwnProperty('createClient')) {
client = mysql.createClient(settings);
} else {
console.log("\nEasyMySQL [WARNING]: node-mysql 0.9.1 support is deprecated.\n");
client = new mysql.Client(settings);
client.connect();
}
cb(null, new EasyClient(client));
}
};
var pool_module = require('generic-pool');
var mysql = require('mysql');
var conn_method = 'createConnection';
if (mysql.hasOwnProperty('createClient')) {
conn_method = 'createClient';
}
/** @ignore */
var pool = {
/** @ignore */
create: function (settings) {
return pool_module.Pool({
name: 'mysql_' + settings.database,
create: function (callback) {
var client;
if (mysql.hasOwnProperty(conn_method)) {
client = mysql[conn_method](settings);
} else {
console.log("\nEasyMySQL [WARNING]: node-mysql 0.9.1 support is deprecated.\n");
EasyClient.fetch = function (settings, cb) {
if (settings.pool) {
get_client_from_pool(settings.pool, cb);
} else if (settings.use_easy_pool) {
var pool = easy_pool.fetch(settings);
get_client_from_pool(pool, cb);
} else {
var client;
if (mysql.hasOwnProperty('createConnection')) {
client = mysql.createConnection(settings);
} else if (mysql.hasOwnProperty('createClient')) {
client = mysql.createClient(settings);
} else {
console.log("\nEasyMySQL [WARNING]: node-mysql 0.9.1 support is deprecated.\n");
client = new mysql.Client(settings);
client.connect();
}
cb(null, new EasyClient(client));
}
};
create: function (callback) {
var client;
if (mysql.hasOwnProperty(conn_method)) {
client = mysql[conn_method](settings);
} else {
console.log("\nEasyMySQL [WARNING]: node-mysql 0.9.1 support is deprecated.\n");
client = new mysql.Client(settings);
client.connect();
}
callback(null, client);
},