Created
September 29, 2017 13:14
-
-
Save existme/bc4252d76199ddf9dbfc432bba652aa8 to your computer and use it in GitHub Desktop.
This script will copy the selected table schemas as markdown tables into the clipboard. #IntelliJ #db #database #extractors #schema
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
import com.intellij.database.model.DasTable | |
import com.intellij.database.model.ObjectKind | |
import com.intellij.database.util.Case | |
import com.intellij.database.util.DasUtil | |
SEPARATOR = "," | |
QUOTE = "\"" | |
NEWLINE = System.getProperty("line.separator") | |
SEPARATOR = File.separator | |
SPACING = " " | |
buffer = new StringBuilder() | |
def calcFields(table) { | |
DasUtil.getColumns(table).reduce([]) { fields, col -> | |
def spec = Case.LOWER.apply(col.getDataType().getSpecification()) | |
fields += [[ | |
name : col.getName(), | |
type : spec, | |
annos: ""]] | |
} | |
} | |
def generate(buffer, table) { | |
def className = table.getName() | |
buffer.append(NEWLINE) | |
buffer.append("## Table: `$className`") | |
buffer.append(NEWLINE).append(NEWLINE) | |
println className | |
buffer.append("| COLUMN | TYPE |").append(NEWLINE) | |
buffer.append("|-------------------------|------------------------|").append(NEWLINE) | |
def fields = calcFields(table) | |
fields.each() { | |
buffer.append("| ${it.name} | ${it.type} | ").append(NEWLINE) | |
} | |
buffer.append(NEWLINE) | |
} | |
SELECTION.filter { it instanceof DasTable && it.getKind() == ObjectKind.TABLE }.each { generate(buffer,it) } | |
CLIPBOARD.set(buffer.toString()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where can i konw the detail of package "com.intellij.database.util.DasUtil"?