Last active
February 28, 2017 18:38
-
-
Save vdakalov/bc80261a74fadb8ffb014c93a46d647f to your computer and use it in GitHub Desktop.
Скрипт для плагина PHPStorm "Database Tools and SQL", который сохраняет таблицы в PHP файлы
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var NEWLINE = "\n", | |
| TAB = " "; | |
| function eachWithIdx(iterable, f) { var i = iterable.iterator(); var idx = 0; while (i.hasNext()) f(i.next(), idx++); } | |
| function output() { for (var i = 0; i < arguments.length; i++) { OUT.append(arguments[i]); } } | |
| output( | |
| "<?php", NEWLINE, NEWLINE, | |
| "return [", | |
| NEWLINE); | |
| eachWithIdx(ROWS, function (row) { | |
| output(TAB, "[", NEWLINE); | |
| eachWithIdx(COLUMNS, function (col, i) { | |
| var data = row.value(col), | |
| type = typeof data, | |
| value = FORMATTER.format(row, col), | |
| skipQuoted = ['boolean', 'number'].indexOf(type) !== -1 || (data === null); | |
| output(TAB, TAB, '"' + col.name() + '" => ' + (skipQuoted ? value : '"' + value.replace(/"/g, '\\"') + '"')); | |
| if (i < COLUMNS.length - 1) { | |
| output(','); | |
| } | |
| output(NEWLINE); | |
| }); | |
| output(TAB, "]", | |
| row.last() ? "" : ",", | |
| NEWLINE); | |
| }); | |
| output("];", NEWLINE); |
Author
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Результат