cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              var keywords = ['ABSOLUTE', 'ACTION', 'ADD', 'AGGR', 'ALL', 'ALTER', 'AND', 'ANTI', 'ANY', 'APPLY', 'ARRAY', 'AS', 'ASSERT', 'ASC', 'ATTACH', 'AUTOINCREMENT', 'AUTO_INCREMENT', 'AVG', 'BEGIN', 'BETWEEN', 'BREAK', 'BY', 'CALL', 'CASE', 'CAST', 'CHECK', 'CLASS', 'CLOSE', 'COLLATE', 'COLUMN', 'COLUMNS', 'COMMIT', 'CONSTRAINT', 'CONTENT', 'CONTINUE', 'CONVERT', 'CORRESPONDING', 'COUNT', 'CREATE', 'CROSS', 'CUBE', 'CURRENT_TIMESTAMP', 'CURSOR', 'DATABASE', 'DECLARE', 'DEFAULT', 'DELETE', 'DELETED', 'DESC', 'DETACH', 'DISTINCT', 'DOUBLEPRECISION', 'DROP', 'ECHO', 'EDGE', 'END', 'ENUM', 'ELSE', 'EXCEPT', 'EXISTS', 'EXPLAIN', 'FALSE', 'FETCH', 'FIRST', 'FOREIGN', 'FROM', 'GO', 'GRAPH', 'GROUP', 'GROUPING', 'HAVING', 'HELP', 'IF', 'IDENTITY', 'IS', 'IN', 'INDEX', 'INNER', 'INSERT', 'INSERTED', 'INTERSECT', 'INTO', 'JOIN', 'KEY', 'LAST', 'LET', 'LEFT', 'LIKE', 'LIMIT', 'LOOP', 'MATCHED', 'MATRIX', 'MAX', 'MERGE', 'MIN', 'MINUS', 'MODIFY', 'NATURAL', 'NEXT', 'NEW', 'NOCASE', 'NO', 'NOT', 'NULL', 'OFF', 'ON', 'ONLY', 'OFFSET', 'OPEN', 'OPTION', 'OR', 'ORDER', 'OUTER', 'OVER', 'PATH', 'PARTITION', 'PERCENT', 'PLAN', 'PRIMARY', 'PRINT', 'PRIOR', 'QUERY', 'READ', 'RECORDSET', 'REDUCE', 'REFERENCES', 'RELATIVE', 'REPLACE', 'REMOVE', 'RENAME', 'REQUIRE', 'RESTORE', 'RETURN', 'RETURNS', 'RIGHT', 'ROLLBACK', 'ROLLUP', 'ROW', 'SCHEMA(S)?', 'SEARCH', 'SELECT', 'SEMI', 'SET', 'SETS', 'SHOW', 'SOME', 'SOURCE', 'STRATEGY', 'STORE', 'SUM', 'TABLE', 'TABLES', 'TARGET', 'TEMP', 'TEMPORARY', 'TEXTSTRING', 'THEN', 'TIMEOUT', 'TO', 'TOP', 'TRAN', 'TRANSACTION', 'TRIGGER', 'TRUE', 'TRUNCATE', 'UNION', 'UNIQUE', 'UPDATE', 'USE', 'USING', 'VALUE', 'VERTEX', 'VIEW', 'WHEN', 'WHERE', 'WHILE', 'WITH', 'WORK'];

var re = new RegExp('^(' + keywords.join('|') + ')$', 'i');
function alasql_formatter(string) {
    return string.split(/(\s+)/).map(function(string) {
        if (re.test(string)) {
            return '[[b;#fff;]' + string + ']';
        } else {
            return string;
        }
    }).join('');
}

$.terminal.defaults.formatters.push(alasql_formatter);

function query(command, term) {
    term.pause();
    alasql(command, [], function(result) {
        if (typeof result == 'number') {
            term.echo(result + ' row' + (result!=1?'s':'') + ' affected', {formatters: false});
        } else if (result.length > 0) {
            var keys = Object.keys(result[0]);
            result = [keys].concat(result.map(function(row) {
                if (row instanceof Array) {
                    return row.map(function(item) {
                        return $.terminal.escape_brackets(String(item));
                    });
                } else {
                    return Object.keys(row).map(function(key) {
                        return $.terminal.escape_brackets(String(row[key]));
                    });
                }
            }));
            term.echo(ascii_table(result, true), {formatters: false});
        }
        term.resume();
    });
}

alasql('CREATE INDEXEDDB DATABASE IF NOT EXISTS MyBase; \
        ATTACH INDEXEDDB DATABASE MyBase; \
        USE MyBase;', [], function() {
    var term = $('body').terminal(function(command, term) {
        if (!command.trim()) {
            return;
        }
        try {
            query(command, term);
        } catch(e) {
            term.error(e.message).resume();
        }
    }, {
        greetings: '[[!;;;;http://alasql.org]alaSQL] ' + alasql.version +
                   '; [[!;;;;http://terminal.jcubic.pl]jQuery Terminal] ' + $.terminal.version,
        name: 'sql',
        prompt: 'sql> ',
        completion: keywords,
        caseSensitiveAutocomplete: false
    });
});





function ascii_table(array, header) {
    if (!array.length) {
        return '';
    }
    for (var i = array.length - 1; i >= 0; i--) {
        var row = array[i];
        var stacks = [];
        for (var j = 0; j < row.length; j++) {
            var new_lines = row[j].toString().split("\n");
            row[j] = new_lines.shift();
            stacks.push(new_lines);
        }
        var new_rows_count = Math.max.apply(Math, stacks.map(function(column) {
            return column.length;
        }));
        for (var k = new_rows_count - 1; k >= 0; k--) {
            array.splice(i + 1, 0, stacks.map(function(column) {
                return column[k] || "";
            }));
        }
    }

    var lengths = array[0].map(function(_, i) {
        var col = array.map(function(row) {
            if (row[i] != undefined) {
                var len = wcwidth(row[i]);
                if (row[i].match(/\t/g)) {
                    // tab is 4 spaces
                    len += row[i].match(/\t/g).length*3;
                }
                return len;
            } else {
                return 0;
            }
        });
        return Math.max.apply(Math, col);
    });
    // column padding
    array = array.map(function(row) {
        return '| ' + row.map(function(item, i) {
            var size = wcwidth(item);
            if (item.match(/\t/g)) {
                // tab is 4 spaces
                size += item.match(/\t/g).length*3;
            }
            if (size < lengths[i]) {
                item += new Array(lengths[i] - size + 1).join(' ');
            }
            return item;
        }).join(' | ') + ' |';
    });
    var sep = '+' + lengths.map(function(length) {
        return new Array(length + 3).join('-');
    }).join('+') + '+';
    if (header) {
        return sep + '\n' + array[0] + '\n' + sep + '\n' +
            array.slice(1).join('\n') + '\n' + sep;
    } else {
        return sep + '\n' + array.join('\n') + '\n' + sep;
    }
}
            
          
!
999px
Loading ..................

Console