{"size": 1792, "ext": "js", "max_stars_repo_path": "exemple/workers/database-create.js", "max_stars_repo_name": "rzorzal/ant-orm", "max_stars_repo_stars_event_min_datetime": "2018-02-01T18:35:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-25T20:06:57.000Z", "max_issues_repo_path": "workers/database-create.js", "max_issues_repo_name": "rzorzal/ant-orm", "max_issues_repo_issues_event_min_datetime": "2018-02-27T19:20:54.000Z", "max_issues_repo_issues_event_max_datetime": "2019-01-04T14:31:34.000Z", "max_forks_repo_path": "exemple/workers/database-create.js", "max_forks_repo_name": "rzorzal/ant-orm", "max_forks_repo_forks_event_min_datetime": "2018-02-27T18:21:27.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-27T18:21:27.000Z"}
{"max_stars_count": 3, "max_issues_count": 2, "max_forks_count": 1, "avg_line_length": 35.84, "max_line_length": 118, "alphanum_fraction": 0.5714285714}
onmessage = async function(e){

    let models = e.data.models;
    let databaseName = e.data.databaseName;
    let version = e.data.version;

    if (!('indexedDB' in this)) {
        console.console.error();('This browser doesn\'t support IndexedDB');
        postMessage({
            error: new Error("This browser doesn\'t support IndexedDB")
        });
        return;
    }

    let dbPromise = indexedDB.open(databaseName, version);

    dbPromise.onupgradeneeded = function(event){
        let DB = event.target.result;
        for(let modelsDefinition of models){
            if (!DB.objectStoreNames.contains(modelsDefinition.modelName)) {
                let table = DB.createObjectStore(modelsDefinition.modelName, {keyPath: 'ANTID', autoIncrement: true});
                for(let columnName in modelsDefinition.columns){
                    if (columnName == 'ANTID') continue;
                    let columnsDefinition = modelsDefinition.columns[columnName];
                    table.createIndex(columnName, columnName, {unique: columnsDefinition.unique});
                }
            } else {
                let tx = event.target.transaction;
                let table = tx.objectStore(modelsDefinition.modelName);
                for(let columnName in modelsDefinition.columns){
                    if (columnName == 'ANTID') continue;
                    if(!table.indexNames.contains(columnName)){
                        let columnsDefinition = modelsDefinition.columns[columnName];
                        table.createIndex(columnName, columnName, {unique: columnsDefinition.unique});
                    }
                }
            }
        }


    }

    dbPromise.onsuccess = function(){
        postMessage({
            success: true,
        });
    }

}
