SQL Formatter for Scala.
This is a bridge to these libraries.
- Running on jvm, calls https://github.com/vertical-blank/sql-formatter
- Running on js, calls https://github.com/zeroturnaround/sql-formatter
You can easily use com.github.vertical_blank.sqlformatter.scala.SqlFormatter :
SqlFormatter.format("SELECT * FROM table1")This will output:
SELECT * FROM table1You can pass dialect :
SqlFormatter.format( "SELECT *", dialect = SqlDialect.CouchbaseN1QL)Currently just four SQL dialects are supported:
- StandardSQL - Standard SQL
- CouchbaseN1QL - Couchbase N1QL
- DB2 - IBM DB2
- PLSQL - Oracle PL/SQL
Defaults to two spaces. You can pass indent string to format :
SqlFormatter.format("SELECT * FROM table1", indent = " ")This will output:
SELECT * FROM table1You can pass Seq to formatWithIndexedParams, or Map to formatWithNamedParams :
// Named placeholders SqlFormatter.formatWithNamedParams("SELECT * FROM tbl WHERE foo = @foo", params = Map("foo" -> "'bar'")) // Indexed placeholders SqlFormatter.formatWithIndexedParams("SELECT * FROM tbl WHERE foo = ?", params = Seq("'bar'"))Both result in:
SELECT * FROM tbl WHERE foo = 'bar'Same as the format method, formatWithNamedParams and formatWithIndexedParams accept dialect and indent parameters.
