<commit_before>"use strict";

const MongoClient = require("mongodb").MongoClient;
const debug = require("debug")("bot-express:memory");
const assert = require('assert');
Promise = require("bluebird");

class MemoryMongodb {
    constructor(options){
        this.url = options.url;
        this.connected = MongoClient.connect(this.url, {promiseLibrary: Promise}).then((response) => {
            this.db = response;
        });
    }

    get(key){
        return this.connected.then((response) => {
            return this.db.collection('bot-express').findOne({context_id: key}).then((response) => {
                return resolve(response);
            }).catch((error) => {
                return reject(error);
            });
        });
    }

    put(key, value, retention){
        return this.connected.then((response) => {
            value.context_id = key;
            return this.db.collection('bot-express').insertOne(value).then((response) => {
                assert.equal(1, response.insertedCount);
                return resolve();
            }).catch((error) => {
                return reject(error);
            });
        });
    }

    del(key){
        return this.connected.then((response) => {
            return this.db.collection('bot-express').deleteOne({context_id: key}).then((response) => {
                assert.equal(null, err);
                return resolve();
            }).catch((error) => {
                return reject(error);
            });
        });
    }
}

module.exports = MemoryMongodb;<commit_msg>improving<commit_after>"use strict";

const MongoClient = require("mongodb").MongoClient;
const debug = require("debug")("bot-express:memory");
const assert = require('assert');
Promise = require("bluebird");

class MemoryMongodb {
    constructor(options){
        this.url = options.url;
        this.connected = MongoClient.connect(this.url, {promiseLibrary: Promise}).then((response) => {
            this.db = response;
        });
    }

    get(key){
        return this.connected.then((response) => {
            return this.db.collection('bot-express').findOne({context_id: key}).then((response) => {
                return response;
            }).catch((error) => {
                return Promise.reject(error);
            });
        });
    }

    put(key, value, retention){
        return this.connected.then((response) => {
            value.context_id = key;
            return this.db.collection('bot-express').insertOne(value).then((response) => {
                assert.equal(1, response.insertedCount);
                return;
            }).catch((error) => {
                return Promise.reject(error);
            });
        });
    }

    del(key){
        return this.connected.then((response) => {
            return this.db.collection('bot-express').deleteOne({context_id: key}).then((response) => {
                assert.equal(null, err);
                return;
            }).catch((error) => {
                return Promise.reject(error);
            });
        });
    }
}

module.exports = MemoryMongodb;
{'fraction_non_alphanumeric': 0.15714746692481446, 'fraction_numerical': 0.0006453694740238787, 'mean_word_length': 2.003875968992248, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '5596549', 'n_tokens_mistral': 845, 'n_tokens_neox': 808, 'n_words': 129}