<commit_before>/*jshint globalstrict: true*/
'use strict';
(function(idbModules, undefined){
    /**
     * IDB Index
     * http://www.w3.org/TR/IndexedDB/#idl-def-IDBIndex
     * @param {Object} name;
     * @param {Object} objectStore;
     */
    function IDBIndex(indexName, idbObjectStore){
        this.indexName = this.name = indexName;
        this.__idbObjectStore = this.objectStore = this.source = idbObjectStore;

        var storeProps = idbObjectStore.transaction.db.__storeProperties[idbObjectStore.name];
        var indexList = storeProps && storeProps.indexList;

        this.keyPath = ((indexList && indexList[indexName] && indexList[indexName].keyPath) || indexName);
        ['multiEntry','unique'].forEach(function(prop){
            this[prop] = !!indexList && !!indexList[indexName] && !!indexList[indexName].optionalParams && !!indexList[indexName].optionalParams[prop];
        }, this);
    }
    
    IDBIndex.prototype.__createIndex = function(indexName, keyPath, optionalParameters){
        var me = this;
        var transaction = me.__idbObjectStore.transaction;
        transaction.__addToTransactionQueue(function(tx, args, success, failure){
            me.__idbObjectStore.__getStoreProps(tx, function(){
                function error(){
                    idbModules.util.throwDOMException(0, "Could not create new index", arguments);
                }
                if (transaction.mode !== 2) {
                    idbModules.util.throwDOMException(0, "Invalid State error, not a version transaction", me.transaction);
                }
                var idxList = JSON.parse(me.__idbObjectStore.__storeProps.indexList);
                if (typeof idxList[indexName] !== "undefined") {
                    idbModules.util.throwDOMException(0, "Index already exists on store", idxList);
                }
                var columnName = indexName;
                idxList[indexName] = {
                    "columnName": columnName,
                    "keyPath": keyPath,
                    "optionalParams": optionalParameters
                };
                // For this index, first create a column
                me.__idbObjectStore.__storeProps.indexList = JSON.stringify(idxList);
                var sql = ["ALTER TABLE", idbModules.util.quote(me.__idbObjectStore.name), "ADD", columnName, "BLOB"].join(" ");
                idbModules.DEBUG && console.log(sql);
                tx.executeSql(sql, [], function(tx, data){
                    // Once a column is created, put existing records into the index
                    tx.executeSql("SELECT * FROM " + idbModules.util.quote(me.__idbObjectStore.name), [], function(tx, data){
                        (function initIndexForRow(i){
                            if (i < data.rows.length) {
                                try {
                                    var value = idbModules.Sca.decode(data.rows.item(i).value);
                                    var indexKey = idbModules.Key.evalKeyPath(keyPath, value);
                                    tx.executeSql("UPDATE " + idbModules.util.quote(me.__idbObjectStore.name) + " set " + columnName + " = ? where key = ?", [idbModules.Key.encode(indexKey), data.rows.item(i).key], function(tx, data){
                                        initIndexForRow(i + 1);
                                    }, error);
                                } 
                                catch (e) {
                                    // Not a valid value to insert into index, so just continue
                                    initIndexForRow(i + 1);
                                }
                            }
                            else {
                                idbModules.DEBUG && console.log("Updating the indexes in table", me.__idbObjectStore.__storeProps);
                                tx.executeSql("UPDATE __sys__ set indexList = ? where name = ?", [me.__idbObjectStore.__storeProps.indexList, me.__idbObjectStore.name], function(){
                                    me.__idbObjectStore.__setReadyState("createIndex", true);
                                    success(me);<commit_msg>wrap all key column names in quotes to support complex keys<commit_after>/*jshint globalstrict: true*/
'use strict';
(function(idbModules, undefined){
    /**
     * IDB Index
     * http://www.w3.org/TR/IndexedDB/#idl-def-IDBIndex
     * @param {Object} name;
     * @param {Object} objectStore;
     */
    function IDBIndex(indexName, idbObjectStore){
        this.indexName = this.name = indexName;
        this.__idbObjectStore = this.objectStore = this.source = idbObjectStore;

        var storeProps = idbObjectStore.transaction.db.__storeProperties[idbObjectStore.name];
        var indexList = storeProps && storeProps.indexList;

        this.keyPath = ((indexList && indexList[indexName] && indexList[indexName].keyPath) || indexName);
        ['multiEntry','unique'].forEach(function(prop){
            this[prop] = !!indexList && !!indexList[indexName] && !!indexList[indexName].optionalParams && !!indexList[indexName].optionalParams[prop];
        }, this);
    }
    
    IDBIndex.prototype.__createIndex = function(indexName, keyPath, optionalParameters){
        var me = this;
        var transaction = me.__idbObjectStore.transaction;
        transaction.__addToTransactionQueue(function(tx, args, success, failure){
            me.__idbObjectStore.__getStoreProps(tx, function(){
                function error(){
                    idbModules.util.throwDOMException(0, "Could not create new index", arguments);
                }
                if (transaction.mode !== 2) {
                    idbModules.util.throwDOMException(0, "Invalid State error, not a version transaction", me.transaction);
                }
                var idxList = JSON.parse(me.__idbObjectStore.__storeProps.indexList);
                if (typeof idxList[indexName] !== "undefined") {
                    idbModules.util.throwDOMException(0, "Index already exists on store", idxList);
                }
                var columnName = indexName;
                idxList[indexName] = {
                    "columnName": columnName,
                    "keyPath": keyPath,
                    "optionalParams": optionalParameters
                };
                // For this index, first create a column
                me.__idbObjectStore.__storeProps.indexList = JSON.stringify(idxList);
                var sql = ["ALTER TABLE", idbModules.util.quote(me.__idbObjectStore.name), "ADD", idbModules.util.quote(columnName), "BLOB"].join(" ");
                idbModules.DEBUG && console.log(sql);
                tx.executeSql(sql, [], function(tx, data){
                    // Once a column is created, put existing records into the index
                    tx.executeSql("SELECT * FROM " + idbModules.util.quote(me.__idbObjectStore.name), [], function(tx, data){
                        (function initIndexForRow(i){
                            if (i < data.rows.length) {
                                try {
                                    var value = idbModules.Sca.decode(data.rows.item(i).value);
                                    var indexKey = idbModules.Key.evalKeyPath(keyPath, value);
                                    tx.executeSql("UPDATE " + idbModules.util.quote(me.__idbObjectStore.name) + " set " + columnName + " = ? where key = ?", [idbModules.Key.encode(indexKey), data.rows.item(i).key], function(tx, data){
                                        initIndexForRow(i + 1);
                                    }, error);
                                } 
                                catch (e) {
                                    // Not a valid value to insert into index, so just continue
                                    initIndexForRow(i + 1);
                                }
                            }
                            else {
                                idbModules.DEBUG && console.log("Updating the indexes in table", me.__idbObjectStore.__storeProps);
                                tx.executeSql("UPDATE __sys__ set indexList = ? where name = ?", [me.__idbObjectStore.__storeProps.indexList, me.__idbObjectStore.name], function(){
                                    me.__idbObjectStore.__setReadyState("createIndex", true);
                                    success(me);
{'fraction_non_alphanumeric': 0.10846089948973538, 'fraction_numerical': 0.0016613266880265813, 'mean_word_length': 1.6781061328249127, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4775202', 'n_tokens_mistral': 2149, 'n_tokens_neox': 2083, 'n_words': 419}