Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
datagrip php array extractor
/*
* 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("[")
values.eachWithIndex { value, idx ->
def str = valueToString(value)
OUT.append("'").append(value.name()).append("' => ")
if(str == "NULL") {
OUT.append(str).append(",")
} else {
OUT.append("'").append(str).append("',")
}
OUT.append(NEWLINE)
}
OUT.append("],")
}
ROWS.each { row -> printRow(COLUMNS, { FORMATTER.format(row, it) }) }
@dacastro4

This comment has been minimized.

Copy link

commented Nov 30, 2018

Works like a charm. Thank you so much!!

@jerfeson

This comment has been minimized.

Copy link

commented Aug 4, 2019

Thank you so much !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.