<commit_before>var mysql = require("mysql");
var Query = require("sql-query").Query;

exports.Driver = Driver;

function Driver(config, connection, opts) {
	this.config = config || {};
	this.opts   = opts || {};
	this.query  = new Query("mysql");

	if (!this.config.timezone) {
		// force UTC if not defined, UTC is always better..
		this.config.timezone = "Z";
	}

	this.reconnect(null, connection);

	this.aggregate_functions = [ "ABS", "CEIL", "FLOOR", "ROUND",
	                             "AVG", "MIN", "MAX",
	                             "LOG", "LOG2", "LOG10", "EXP", "POWER",
	                             "ACOS", "ASIN", "ATAN", "COS", "SIN", "TAN",
	                             "CONV", [ "RANDOM", "RAND" ], "RADIANS", "DEGREES",
	                             "SUM", "COUNT",
	                             "DISTINCT" ];
}

Driver.prototype.sync = function (opts, cb) {
	return require("../DDL/mysql").sync(this, opts, cb);
};

Driver.prototype.drop = function (opts, cb) {
	return require("../DDL/mysql").drop(this, opts, cb);
};

Driver.prototype.ping = function (cb) {
	this.db.ping(cb);
	return this;
};

Driver.prototype.on = function (ev, cb) {
	if (ev == "error") {
		this.db.on("error", cb);
		this.db.on("unhandledError", cb);
	}
	return this;
};

Driver.prototype.connect = function (cb) {
	if (this.opts.pool) {
		return this.db.pool.getConnection(function (err, con) {
			if (!err) {
				con.end();
			}
			return cb(err);
		});
	}
	this.db.connect(cb);
};

Driver.prototype.reconnect = function (cb, connection) {
	this.db = (connection ? connection : mysql.createConnection(this.config.href || this.config));
	if (this.opts.pool) {
		this.db.pool = (connection ? connection : mysql.createPool(this.config.href || this.config));
	}
	if (typeof cb == "function") {
		this.connect(cb);
	}
};

Driver.prototype.close = function (cb) {
	if (this.opts.pool) {
		return cb();
	}<commit_msg>Avoids throwing when calling db.close() without a callback and using pool in mysql (fixes #180)<commit_after>var mysql = require("mysql");
var Query = require("sql-query").Query;

exports.Driver = Driver;

function Driver(config, connection, opts) {
	this.config = config || {};
	this.opts   = opts || {};
	this.query  = new Query("mysql");

	if (!this.config.timezone) {
		// force UTC if not defined, UTC is always better..
		this.config.timezone = "Z";
	}

	this.reconnect(null, connection);

	this.aggregate_functions = [ "ABS", "CEIL", "FLOOR", "ROUND",
	                             "AVG", "MIN", "MAX",
	                             "LOG", "LOG2", "LOG10", "EXP", "POWER",
	                             "ACOS", "ASIN", "ATAN", "COS", "SIN", "TAN",
	                             "CONV", [ "RANDOM", "RAND" ], "RADIANS", "DEGREES",
	                             "SUM", "COUNT",
	                             "DISTINCT" ];
}

Driver.prototype.sync = function (opts, cb) {
	return require("../DDL/mysql").sync(this, opts, cb);
};

Driver.prototype.drop = function (opts, cb) {
	return require("../DDL/mysql").drop(this, opts, cb);
};

Driver.prototype.ping = function (cb) {
	this.db.ping(cb);
	return this;
};

Driver.prototype.on = function (ev, cb) {
	if (ev == "error") {
		this.db.on("error", cb);
		this.db.on("unhandledError", cb);
	}
	return this;
};

Driver.prototype.connect = function (cb) {
	if (this.opts.pool) {
		return this.db.pool.getConnection(function (err, con) {
			if (!err) {
				con.end();
			}
			return cb(err);
		});
	}
	this.db.connect(cb);
};

Driver.prototype.reconnect = function (cb, connection) {
	this.db = (connection ? connection : mysql.createConnection(this.config.href || this.config));
	if (this.opts.pool) {
		this.db.pool = (connection ? connection : mysql.createPool(this.config.href || this.config));
	}
	if (typeof cb == "function") {
		this.connect(cb);
	}
};

Driver.prototype.close = function (cb) {
	if (this.opts.pool) {
		if (typeof cb == "function") cb();
		return;
	}
{'fraction_non_alphanumeric': 0.18794506612410986, 'fraction_numerical': 0.002288911495422177, 'mean_word_length': 2.679139382600561, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3794258', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1338, 'n_words': 296}