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

exports.Driver = Driver;

function Driver(config, connection, opts) {
	var functions = switchableFunctions.client;
	this.config = config || {};
	this.opts   = opts || {};
	this.query  = new Query("postgresql");

	if (connection) {
		this.db = connection;
	} else {
		if (config.query && config.query.ssl) {
			config.ssl = true;
			this.config = config;
		} else {
			this.config = config.href || config;
		}

		if (opts.pool) {
			functions = switchableFunctions.pool;
			this.db = pg;
		} else {
			this.db = new pg.Client(this.config);
		}
	}

	for (var name in functions) {
		this.constructor.prototype[name] = functions[name];
	}

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

var switchableFunctions = {
	pool: {
		connect: function (cb) {
			this.db.connect(this.config, function (err, client, done) {
				if(!err) done()
				cb(err);
			});
		},
		execQuery: function (query, cb) {
			this.db.connect(this.config, function (err, client, done) {
				if (err) return cb(err);

				client.query(query, function (err, result) {
					done();

					if(err) {
						cb(err);
					} else {
						cb(null, result.rows);
					}
				});
			});
			return this;
		},
		on: function(ev, cb) {
			// Because `pg` is the same for all instances of this driver
			// we can't keep adding listeners since they are never removed.
			return this;
		}
	},
	client: {
		connect: function (cb) {
			this.db.connect(cb);
		},
		execQuery: function (query, cb) {
			this.db.query(query, function(err, result) {
				if(err) {
					cb(err);
				} else {
					cb(null, result.rows);
				}
			});
			return this;
		},
		on: function(ev, cb) {
			if (ev == "error") {
				this.db.on("error", cb);
			}
			return this;
		}
	}
}

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

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

Driver.prototype.ping = function (cb) {
	this.execQuery("SELECT * FROM pg_stat_activity LIMIT 1", function () {
		return cb();
	});
	return this;
};

Driver.prototype.close = function (cb) {
	this.db.end(cb);
};

Driver.prototype.getQuery = function () {
	return this.query;
};
<commit_msg>Lints postgres driver<commit_after>var pg    = require("pg");
var Query = require("sql-query").Query;

exports.Driver = Driver;

function Driver(config, connection, opts) {
	var functions = switchableFunctions.client;
	this.config = config || {};
	this.opts   = opts || {};
	this.query  = new Query("postgresql");

	if (connection) {
		this.db = connection;
	} else {
		if (config.query && config.query.ssl) {
			config.ssl = true;
			this.config = config;
		} else {
			this.config = config.href || config;
		}

		if (opts.pool) {
			functions = switchableFunctions.pool;
			this.db = pg;
		} else {
			this.db = new pg.Client(this.config);
		}
	}

	for (var name in functions) {
		this.constructor.prototype[name] = functions[name];
	}

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

var switchableFunctions = {
	pool: {
		connect: function (cb) {
			this.db.connect(this.config, function (err, client, done) {
				if (!err) done();
				cb(err);
			});
		},
		execQuery: function (query, cb) {
			this.db.connect(this.config, function (err, client, done) {
				if (err) return cb(err);

				client.query(query, function (err, result) {
					done();

					if (err) {
						cb(err);
					} else {
						cb(null, result.rows);
					}
				});
			});
			return this;
		},
		on: function(ev, cb) {
			// Because `pg` is the same for all instances of this driver
			// we can't keep adding listeners since they are never removed.
			return this;
		}
	},
	client: {
		connect: function (cb) {
			this.db.connect(cb);
		},
		execQuery: function (query, cb) {
			this.db.query(query, function(err, result) {
				if(err) {
					cb(err);
				} else {
					cb(null, result.rows);
				}
			});
			return this;
		},
		on: function(ev, cb) {
			if (ev == "error") {
				this.db.on("error", cb);
			}
			return this;
		}
	}
};

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

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

Driver.prototype.ping = function (cb) {
	this.execQuery("SELECT * FROM pg_stat_activity LIMIT 1", function () {
		return cb();
	});
	return this;
};

Driver.prototype.close = function (cb) {
	this.db.end(cb);
};

Driver.prototype.getQuery = function () {
	return this.query;
};

{'fraction_non_alphanumeric': 0.16987542468856173, 'fraction_numerical': 0.00037750094375235937, 'mean_word_length': 2.381620931716656, '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': '7630208', 'n_tokens_mistral': 2094, 'n_tokens_neox': 1810, 'n_words': 422}