Created
April 26, 2019 16:18
-
-
Save BiggerNoise/d499cac984785807d0b5f833291a86b1 to your computer and use it in GitHub Desktop.
This will allow DataGrip results to be copied to the clipboard in a slack friendly markdown format.
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
SLACK_CODE = "```" | |
SEP = "|" | |
NEWLINE = System.getProperty("line.separator") | |
def scan(ROWS, COLUMNS) { | |
result = [] | |
result.add(COLUMNS.collect { col -> col.name() }) | |
ROWS.each { row -> result.add(COLUMNS.collect { col -> row.value(col).toString() }) } | |
return result | |
} | |
def size(extract) { | |
return extract.collect { row -> row*.length() }.inject([]) { result, r -> | |
r.eachWithIndex { v, idx -> | |
if (result[idx] == null || result[idx] < v) { | |
result[idx] = v | |
} | |
} | |
return result | |
} | |
} | |
def writeRow(row) { | |
OUT.append(SEP) | |
row.eachWithIndex {v,idx -> | |
OUT.append(v.padLeft(sizes[idx] +1).padRight(sizes[idx] + 2)) | |
OUT.append(SEP) | |
} | |
OUT.append(NEWLINE) | |
} | |
def writeHSeparator(sizes) { | |
OUT.append(SEP) | |
sizes.eachWithIndex {v,idx -> | |
OUT.append(''.padLeft(sizes[idx] +2, '-')) | |
OUT.append(SEP) | |
} | |
OUT.append(NEWLINE) | |
} | |
def record(extract) { | |
OUT.append(SLACK_CODE) | |
OUT.append(NEWLINE) | |
sizes = size(extract) | |
extract.eachWithIndex { r, idx -> | |
if (idx == 1) { | |
writeHSeparator(sizes) | |
} | |
writeRow(r) | |
} | |
OUT.append(SLACK_CODE) | |
OUT.append(NEWLINE) | |
} | |
extract = scan(ROWS, COLUMNS) | |
record(extract) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment