Last active
May 25, 2021 17:40
-
-
Save progerio/cbb80a71fd8f636afe01e7cb934a8c75 to your computer and use it in GitHub Desktop.
Extractor database SQL-php-array- PHPSTORM
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
function eachWithIdx(iterable, f) { | |
var i = iterable.iterator(); | |
var idx = 0; | |
while (i.hasNext()) f(i.next(), idx++); | |
} | |
function repeatStringNumTimes(string, times) { | |
var repeatedString = ""; | |
while (times > 0) { | |
repeatedString += string; | |
times--; | |
} | |
return repeatedString; | |
} | |
function getQtdSpace() { | |
var sizeCols = []; | |
mapEach(COLUMNS, function (col) { | |
sizeCols.push(col.name().length) | |
} | |
); | |
sizeCols.sort(function (a, b) { | |
return a - b; | |
}); | |
return sizeCols[sizeCols.length - 1] + 1; | |
} | |
function mapEach(iterable, f) { | |
var vs = []; | |
eachWithIdx(iterable, function (i) { | |
vs.push(f(i)); | |
}); | |
return vs; | |
} | |
function escape(str) { | |
str = str.replaceAll("\t|\b|\\f", ""); | |
str = com.intellij.openapi.util.text.StringUtil.escapeXml(str); | |
str = str.replaceAll("\\r|\\n|\\r\\n", "<br/>"); | |
return str; | |
} | |
var NEWLINE = "\n"; | |
function output() { | |
for (var i = 0; i < arguments.length; i++) { | |
OUT.append(arguments[i]); | |
} | |
} | |
function outputRow(items, tag) { | |
output("["); | |
for (var i = 0; i < items.length; i++) { | |
var sep = ","; | |
if (i == (items.length - 1)) { | |
sep = ''; | |
} | |
output(NEWLINE, escape(items[i]) + sep, NEWLINE); | |
} | |
output("]", NEWLINE); | |
} | |
if (TRANSPOSED) { | |
var values = mapEach(COLUMNS, function (col) { | |
return [col.name()]; | |
}); | |
eachWithIdx(ROWS, function (row) { | |
eachWithIdx(COLUMNS, function (col, i) { | |
values[i].push(FORMATTER.format(row, col)); | |
}); | |
}); | |
eachWithIdx(COLUMNS, function (_, i) { | |
outputRow(values[i], "td"); | |
}); | |
} else { | |
var qtdSpace = getQtdSpace(); | |
var schema = TABLE.getDbParent().getName(); | |
output("'" + schema + "." + TABLE.getName() + "'", "", ' => [', NEWLINE); | |
eachWithIdx( | |
ROWS, function (row) { | |
output("[", NEWLINE); | |
mapEach(COLUMNS, function (col) { | |
var conteudo = FORMATTER.format(row, col); | |
var colName = col.name(); | |
var spaceDefault = (qtdSpace - colName.length); | |
var space = repeatStringNumTimes(" ", spaceDefault); | |
if(conteudo === 'false'){ | |
conteudo = 0; | |
} | |
if (conteudo === 'NULL' || conteudo === 'true') { | |
output("'" + colName + "'" + space + "=> " + conteudo.toLowerCase() + ",", NEWLINE); | |
} else { | |
output("'" + colName + "'" + space + "=> '" + conteudo + "',", NEWLINE); | |
} | |
} | |
); | |
output( "]"); | |
output(",", NEWLINE); | |
} | |
); | |
output("]", NEWLINE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Format value false for 0 (zero)