Skip to content

Instantly share code, notes, and snippets.

@vdakalov
Last active February 28, 2017 18:38
Show Gist options
  • Select an option

  • Save vdakalov/bc80261a74fadb8ffb014c93a46d647f to your computer and use it in GitHub Desktop.

Select an option

Save vdakalov/bc80261a74fadb8ffb014c93a46d647f to your computer and use it in GitHub Desktop.
Скрипт для плагина PHPStorm "Database Tools and SQL", который сохраняет таблицы в PHP файлы
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);
@vdakalov
Copy link
Author

Результат

<?php

return [
    [
        "COLUMN_NAME" => "CELL_VALUE",
        "..." => "..."
    ]
];

@vdakalov
Copy link
Author

vdakalov commented Feb 28, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment