alpine:edge
-based dockerization of sql-formatter the util for formatting SQL queries
As the site says:
SQL Formatter is a JavaScript library for pretty-printing SQL queries [...] SQL formatter supports the following dialects:
- sql - Standard SQL
- mariadb - MariaDB
- mysql - MySQL
- postgresql - PostgreSQL
- db2 - IBM DB2
- plsql - Oracle PL/SQL
- n1ql - Couchbase N1QL
- redshift - Amazon Redshift
- spark - Spark
- tsql - SQL Server Transact-SQL
The source code for this image is hosted on GitHub in the backplane/conex repo.
The following shell function can assist in running this image interactively:
sql_formatter() {
docker run \
--rm \
--interactive \
--tty \
--volume "$(pwd):/work" \
"backplane/sql-formatter" \
"$@"
}
when run interactively with the -h
argument, the container produces the following usage text:
usage: sql-formatter [-h] [-o OUTPUT] [--fix]
[-l {bigquery,db2,hive,mariadb,mysql,n1ql,plsql,postgresql,redshift,spark,sqlite,sql,trino,transactsql,tsql,singlestoredb,snowflake}]
[-c CONFIG] [--version]
[FILE]
SQL Formatter
positional arguments:
FILE Input SQL file (defaults to stdin)
optional arguments:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
File to write SQL output (defaults to stdout)
--fix Update the file in-place
-l {bigquery,db2,hive,mariadb,mysql,n1ql,plsql,postgresql,redshift,spark,sqlite,sql,trino,transactsql,tsql,singlestoredb,snowflake}, --language {bigquery,db2,hive,mariadb,mysql,n1ql,plsql,postgresql,redshift,spark,sqlite,sql,trino,transactsql,tsql,singlestoredb,snowflake}
SQL Formatter dialect (defaults to basic sql)
-c CONFIG, --config CONFIG
Path to config json file (will use default configs if unspecified)
--version show program's version number and exit