-
-
Save redthor/a4f20da4c0483fb294bcdeb763a7302f to your computer and use it in GitHub Desktop.
datagrip php array extractor
This file contains 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
/* | |
* Available context bindings: | |
* COLUMNS List<DataColumn> | |
* ROWS Iterable<DataRow> | |
* OUT { append() } | |
* FORMATTER { format(row, col); formatValue(Object, col) } | |
* TRANSPOSED Boolean | |
* plus ALL_COLUMNS, TABLE, DIALECT | |
* | |
* where: | |
* DataRow { rowNumber(); first(); last(); data(): List<Object>; value(column): Object } | |
* DataColumn { columnNumber(), name() } | |
*/ | |
SEPARATOR = "," | |
QUOTE = "\'" | |
NEWLINE = System.getProperty("line.separator") | |
count = 0; | |
def printRow = { values, valueToString -> | |
OUT.append("[\n") | |
values.eachWithIndex { value, idx -> | |
def str = valueToString(value) | |
OUT.append(" '").append(value.name()).append("' => ") | |
if(str == "NULL" || str.isNumber()) { | |
OUT.append(str).append(",") | |
} else { | |
OUT.append("'").append(str).append("',") | |
} | |
OUT.append(NEWLINE) | |
} | |
OUT.append("],\n") | |
} | |
ROWS.each { row -> printRow(COLUMNS, { FORMATTER.format(row, it) }) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I added the
str.isNumber()
so that numbers do not have apostrophes.Also a little bit of formatting for readability.