<commit_before>/**
 * Copyright (c) 2015 <NAME>
 * BluJagu, LLC - www.blujagu.com
 * MIT License (MIT) - This header must remain intact.
 **/
define(['./eventHub'], function(eventHub) {
    'use strict';

    var _memory = {};

    _memory.__proto__ = {
        'create': function (dbName) {
            this[dbName] = eventHub.connect(new DB(dbName));

            return this[dbName];
        },
        'drop': function (dbName) {
            if (this[dbName]) {
                this[dbName] = null;
                delete this[dbName];

                return true;
            }

            return false;
        },
        'get': function (dbName) {
            return this[dbName];
        }
    };

    var DB = function (dbName) {
        this.__proto__._event = dbName;
    };

    DB.prototype = {
        'constructor': DB,
        '_event': '',
        'createTable': function (tableName) {
            /**
             * createTable adds a new Table Object <tableName> to the DB Object
             *             dispatches a 'tableName' event for any event listeners
             * @param {String} tableName Name to assign to the new table
             * @returns {Function} Returns a curried function waiting for the columns argument
             */
            return function (/*columns*/) {
                var db = this.db,
                    columns = Array.prototype.slice.call(arguments),
                    path = db._event,
                    table = new Table(columns, db, path + '.' + this.tableName),
                    detail;

                db[tableName] = table;
                detail = {
                    'target': this,
                    'type': 'Create',
                    'value': table
                };
                // todo: unlock dispatch
                //this.dispatch(path, detail);
                return table;
            }.bind({
                'db': this,
                'tableName': tableName
            });
        },
        'drop': function (tableName) {
            if (this[tableName]) {
                this[tableName] = null;
                delete this[tableName];
                return true;
            }
        },
        'select': function (/*columns*/) {
            var fromFunc = function (tableName) {
                var curriedSelect = function () {
                        return curriedSelect._return;
                    },
                    table = this.db[tableName],
                    returnObj = {},
                    returnArray = [],
                    returnClone,
                    columns = this.columns[0] === '*' ? Object.keys(table) : this.columns,
                    column = columns.shift(),
                    selected = table[column],
                    selectedVal = undefined,
                    i = 0, j = 0,
                    iLen = selected.length,
                    jLen = columns.length;

                for (i; i < iLen; ++i) {
                    selectedVal = selected[i];
                    if (selectedVal !== null) { // skip holes, these are 'dead indices'
                        returnObj[column] = selectedVal;
                        for (j = 0; j < jLen; ++j) {
                            column = columns[j];
                            selected = table[column];
                            returnObj[column] = selected[i];
                        }
                        returnArray.push(returnObj);
                        returnObj = {};
                    }<commit_msg>SQLish - fixed select when multiple columns returned<commit_after>/**
 * Copyright (c) 2015 <NAME>
 * BluJagu, LLC - www.blujagu.com
 * MIT License (MIT) - This header must remain intact.
 **/
define(['./eventHub'], function(eventHub) {
    'use strict';

    var _memory = {};

    _memory.__proto__ = {
        'create': function (dbName) {
            this[dbName] = eventHub.connect(new DB(dbName));

            return this[dbName];
        },
        'drop': function (dbName) {
            if (this[dbName]) {
                this[dbName] = null;
                delete this[dbName];

                return true;
            }

            return false;
        },
        'get': function (dbName) {
            return this[dbName];
        }
    };

    var DB = function (dbName) {
        this.__proto__._event = dbName;
    };

    DB.prototype = {
        'constructor': DB,
        '_event': '',
        'createTable': function (tableName) {
            /**
             * createTable adds a new Table Object <tableName> to the DB Object
             *             dispatches a 'tableName' event for any event listeners
             * @param {String} tableName Name to assign to the new table
             * @returns {Function} Returns a curried function waiting for the columns argument
             */
            return function (/*columns*/) {
                var db = this.db,
                    columns = Array.prototype.slice.call(arguments),
                    path = db._event,
                    table = new Table(columns, db, path + '.' + this.tableName),
                    detail;

                db[tableName] = table;
                detail = {
                    'target': this,
                    'type': 'Create',
                    'value': table
                };
                // todo: unlock dispatch
                //this.dispatch(path, detail);
                return table;
            }.bind({
                'db': this,
                'tableName': tableName
            });
        },
        'drop': function (tableName) {
            if (this[tableName]) {
                this[tableName] = null;
                delete this[tableName];
                return true;
            }
        },
        'select': function (/*columns*/) {
            var fromFunc = function (tableName) {
                var curriedSelect = function () {
                        return curriedSelect._return;
                    },
                    table = this.db[tableName],
                    returnObj = {},
                    returnArray = [],
                    returnClone,
                    columns = this.columns[0] === '*' ? Object.keys(table) : this.columns,
                    column = columns[0],
                    selected = table[column],
                    selectedVal = undefined,
                    i = 0, j,
                    iLen = selected.length,
                    jLen = columns.length;

                for (i; i < iLen; ++i) {
                    selectedVal = selected[i];
                    if (selectedVal !== null) { // skip holes, these are 'dead indices'
                        returnObj[column] = selectedVal;
                        for (j = 1; j < jLen; ++j) {
                            column = columns[j];
                            selected = table[column];
                            returnObj[column] = selected[i];
                        }
                        returnArray.push(returnObj);
                        column = columns[0];
                        selected = table[column];
                        returnObj = {};
                    }
{'fraction_non_alphanumeric': 0.10832287745713091, 'fraction_numerical': 0.002369998605883173, 'mean_word_length': 1.0927654609101516, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '292178', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1663, 'n_words': 445}