Skip to content

Instantly share code, notes, and snippets.

@existme
Created September 29, 2017 13:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save existme/bc4252d76199ddf9dbfc432bba652aa8 to your computer and use it in GitHub Desktop.
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
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())
@captainIT
Copy link

where can i konw the detail of package "com.intellij.database.util.DasUtil"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment