<commit_before>var PulsarRedisDB = require('./db/redis');
var PulsarMongoDB = require('./db/mongo');

module.exports = (function() {

	var PulsarDB = function(host, port, engine) {
		this.taskList = {};
		if (engine == 'mongo') {
			this.db = new PulsarMongoDB(host, port);
			return;
		}
		this.db = new PulsarRedisDB(host, port);
	}

	PulsarDB.prototype.getUniqueTaskID = function() {
		return this.db.getUniqueTaskID();
	}

	PulsarDB.prototype.saveTask = function(task) {
		this.taskList[task.id] = task;
	}

	PulsarDB.prototype.getTask = function(taskId) {
		if (typeof this.taskList[taskId] !== 'undefined') {
			return this.taskList[taskId];
		}
		throw Error("Task id: " + taskId + " doesn't exist.");
	}

	PulsarDB.prototype.getTaskList = function() {
		return this.taskList;
	}

	PulsarDB.prototype.connect = function() {
		this.db.connect();
	}

	return PulsarDB;

})();<commit_msg>Implemented PulsarDB with mongoDB backend<commit_after>var MongoClient = require('mongodb');

module.exports = (function () {

    var PulsarDB = function (host, port) {
        this.connect(
            host || 'localhost',
            port || 27017
        );
    }

    PulsarDB.MONGO_DB_NAME = 'pulsar';
    PulsarDB.MONGO_COLLECTION_NAME = 'tasks';

    PulsarDB.prototype.getUniqueTaskID = function () {
        return MongoClient.ObjectID().toString();
    }

    PulsarDB.prototype.saveTask = function (task, callback) {
        this.collection.insert({_id: task.id, data: task.getData()}, function (err, focs) {
            callback(task);
        });
    }

    PulsarDB.prototype.getTask = function (taskId, callback) {
        this.collection.findOne({_id: taskId}, function (err, results) {
            callback(err, results);
        });
    }

    PulsarDB.prototype.getTaskList = function (callback) {
        this.collection.find().toArray(function (err, results) {
            callback(err, results);
        });
    }

    PulsarDB.prototype.connect = function (host, port) {
        var self = this;
        var url = 'mongodb://' + host + ':' + port + '/' + PulsarDB.MONGO_DB_NAME;

        MongoClient.connect(url, function (err, db) {
            if (err) {
                throw err;
            }
            self.db = db;
            self.collection = db.collection(PulsarDB.MONGO_COLLECTION_NAME);
        });

    }

    return PulsarDB;

})();
{'fraction_non_alphanumeric': 0.1455160744500846, 'fraction_numerical': 0.0021150592216582064, 'mean_word_length': 2.6609907120743035, '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': '1825510', 'n_tokens_mistral': 835, 'n_tokens_neox': 786, 'n_words': 142}