<commit_before>class DB {

    constructor(idb, idbKey, settings, isWebWorker) {
        this.db = idb;
        this.idbKey = idbKey;
        this.settings = settings;
        this.isWebWorker = isWebWorker || false;
    }

    /**
     * Initializes database connection with indexedDB
     *
     * @returns {Promise}
     */
    connect() {
        let db = this;
        return new Promise((resolve, reject) => {

            if(db.isWebWorker){
                db.createWorkerHandler(resolve, reject);
            }else{
                db.createNormalHandler(resolve, reject);
            }
        });
    }

    /**
     * Destroys/Deletes the databaase
     * @param dbName
     */
    destroy(dbName) {
        console.info('database ' + dbName + ' deleted');
        this.db.deleteDatabase(dbName);
    }

    /**
     * Creates connection in web worker space and if web worker fails
     * then creates normal database connection instance
     * @param resolve
     * @param reject
     */
    createWorkerHandler (resolve, reject) {
        let db = this;
        try{
            let worker = new window.Worker('/indexeddb/src/worker.js');
            let models = {};
            let timestamp = Date.now();

            worker.postMessage({
                detail : JSON.stringify(db.settings),
                action : 'initialize',
                timestamp : timestamp
            });
            
            worker.onmessage = function (e) {
                if(e.data.action === 'initialize' && e.data.timestamp === timestamp) {
                    if (e.data.detail === true) {
                        db.settings.migrations.forEach((schema) => {
                            Object.defineProperty(models, schema.name, {
                                get() {
                                    return new WorkerModelHandler(schema.name, worker, window);
                                }
                            });
                        });
                        resolve(models);
                    } else {
                        db.createNormalHandler(resolve, reject);
                    }
                }
            }

        }catch (e) {
            reject(e);
        }

    }

    /**
     * Creates normal database instance and models
     * @param resolve
     * @param reject
     */
    createNormalHandler (resolve, reject) {
        let db = this;

        let request = this.db.open(this.settings.dbName, this.settings.dbVersion);<commit_msg>change flag name to hanlde usage of web worker<commit_after>class DB {

    constructor(idb, idbKey, settings, useWebWorker) {
        this.db = idb;
        this.idbKey = idbKey;
        this.settings = settings;
        this.useWebWorker = useWebWorker || false;
        this.isWebWorker = false;
    }

    /**
     * Initializes database connection with indexedDB
     *
     * @returns {Promise}
     */
    connect() {
        let db = this;
        return new Promise((resolve, reject) => {

            if(db.useWebWorker){
                db.createWorkerHandler(resolve, reject);
            }else{
                db.createNormalHandler(resolve, reject);
            }
        });
    }

    /**
     * Destroys/Deletes the databaase
     * @param dbName
     */
    destroy(dbName) {
        console.info('database ' + dbName + ' deleted');
        this.db.deleteDatabase(dbName);
    }

    /**
     * Creates connection in web worker space and if web worker fails
     * then creates normal database connection instance
     * @param resolve
     * @param reject
     */
    createWorkerHandler (resolve, reject) {
        let db = this;
        try{
            let worker = new window.Worker('/indexeddb/src/worker.js');
            let models = {};
            let timestamp = Date.now();

            worker.postMessage({
                detail : JSON.stringify(db.settings),
                action : 'initialize',
                timestamp : timestamp
            });
            
            worker.onmessage = function (e) {
                if(e.data.action === 'initialize' && e.data.timestamp === timestamp) {
                    if (e.data.detail === true) {
                        db.settings.migrations.forEach((schema) => {
                            Object.defineProperty(models, schema.name, {
                                get() {
                                    return new WorkerModelHandler(schema.name, worker, window);
                                }
                            });
                        });

                        db.isWebWorker = true;
                        resolve(models);
                    } else {
                        db.createNormalHandler(resolve, reject);
                    }
                }
            }

        }catch (e) {
            reject(e);
        }

    }

    /**
     * Creates normal database instance and models
     * @param resolve
     * @param reject
     */
    createNormalHandler (resolve, reject) {
        let db = this;

        let request = this.db.open(this.settings.dbName, this.settings.dbVersion);
{'fraction_non_alphanumeric': 0.10373850068506557, 'fraction_numerical': 0.0, 'mean_word_length': 1.289426523297491, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6553753', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1246, 'n_words': 283}