Skip to content

Instantly share code, notes, and snippets.

@hfhbd
Last active March 24, 2022 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hfhbd/7ffb4b94e7f9b9035939e26b40999532 to your computer and use it in GitHub Desktop.
Save hfhbd/7ffb4b94e7f9b9035939e26b40999532 to your computer and use it in GitHub Desktop.
Latex extractor for IntelliJ Ultimate Database Tool
import com.intellij.database.extensions.*
/*
* 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() }
*/
val out = bindings["OUT"] as java.lang.Appendable
val columns = bindings["COLUMNS"] as List<DataColumn>
val rows = bindings["ROWS"] as Iterable<DataRow>
val format = bindings["FORMATTER"] as ValueFormatter
out.apply {
append(
"""
\begin{table}[]
\centering
""".trimIndent()
)
append("\\begin{tabular}{${columns.joinToString(separator = "|") { "l" }}}")
appendLine()
append(columns.joinToString(separator = " & ", postfix = """\\ \hline""") {
it.name()
})
for (row in rows) {
appendLine()
append(columns.joinToString(separator = " & ", postfix = """\\""") {
format.format(row, it)
})
}
append("""
\end{tabular}
\caption{}
\label{tab:}
\end{table}
""")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment