<commit_before>var mongo = require('mongodb'),
    utils = require('node-utils'),
    events = new (require('events').EventEmitter)();

function errorCallback(callback) {
    return function(err) {
        if (err) {
            console.log('DB error occurred:');
            console.log(err);

            events.emit('dberror', err);
            return;
        }

        callback && callback.apply(this, utils.shift(arguments));
    };
}

exports.connect = function(dbname, dbhost, dbport, callback) {
    var db = new mongo.Db(dbname, new mongo.Server(
        dbhost, dbport, {auto_reconnect: true}, {}));

    db.open(errorCallback(function() { callback(db); }));
};

exports.createCollection = function(db, name, callback) {
    db.createCollection(name, errorCallback(callback));
};

exports.drop = function(db, callback) {
    db.dropDatabase(errorCallback(callback));
};

/**
 * Registers a handler for database errors
 */
exports.onError = function(handler) {
    events.on('dberror', handler);
};<commit_msg>Added getCollection method and exported errorCallback<commit_after>var mongo = require('mongodb'),
    utils = require('node-utils'),
    events = new (require('events').EventEmitter)();

var errorCallback = exports.errorCallback = function(callback) {
    return function(err) {
        if (err) {
            console.log('DB error occurred:');
            console.log(err);

            events.emit('dberror', err);
            return;
        }

        callback && callback.apply(this, utils.shift(arguments));
    };
};

exports.connect = function(dbname, dbhost, dbport, callback) {
    var db = new mongo.Db(dbname, new mongo.Server(
        dbhost, dbport, {auto_reconnect: true}, {}));

    db.open(errorCallback(function() { callback(db); }));
};

exports.createCollection = function(db, name, callback) {
    db.createCollection(name, errorCallback(callback));
};

exports.getCollection = function(db, name, callback) {
    db.collection(name, errorCallback(callback));
};

exports.drop = function(db, callback) {
    db.dropDatabase(errorCallback(callback));
};

/**
 * Registers a handler for database errors
 */
exports.onError = function(handler) {
    events.on('dberror', handler);
};
{'fraction_non_alphanumeric': 0.15211521152115212, 'fraction_numerical': 0.0, 'mean_word_length': 3.4909090909090907, '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': '3411670', 'n_tokens_mistral': 653, 'n_tokens_neox': 651, 'n_words': 135}