vertical-blank/sql-formatter
vertical-blank/sql-formatter has 272 GitHub stars and 51 forks. Star changes are not measured yet. Last checked 2026-11-14 02:18 UTC. Last push 2024-04-09.
Crecimiento de estrellas medido
- in 24h
- Recopilando historial
- in 7 days
- Recopilando historial
- in 15 days
- Recopilando historial
- in 1 month
- Recopilando historial
Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.
Acerca de
SQL formatter written with only Java Standard Library, without dependencies.
DatosREADME.md
Originalsql-formatter
Java port of great SQL formatter https://github.com/zeroturnaround/sql-formatter.
Written with only Java Standard Library, without dependencies.
Demo is running on Google Cloud Function, with native-compiled shared library by GraalVM.
This does not support:
- Stored procedures.
- Changing of the delimiter type to something else than ;.
Usage
Maven
<dependency>
<groupId>com.github.vertical-blank</groupId>
<artifactId>sql-formatter</artifactId>
<version>2.0.5</version>
</dependency>
Gradle
implementation 'com.github.vertical-blank:sql-formatter:2.0.5'
Examples
You can easily use com.github.vertical_blank.sqlformatter.SqlFormatter :
SqlFormatter.format("SELECT * FROM table1")
This will output:
SELECT
*
FROM
table1
You can also pass FormatConfig object built by builder:
SqlFormatter.format('SELECT * FROM tbl',
FormatConfig.builder()
.indent(" ") // Defaults to two spaces
.uppercase(true) // Defaults to false (not safe to use when SQL dialect has case-sensitive identifiers)
.linesBetweenQueries(2) // Defaults to 1
.maxColumnLength(100) // Defaults to 50
.params(Arrays.asList("a", "b", "c")) // Map or List. See Placeholders replacement.
.build()
);
Dialect
You can pass dialect com.github.vertical_blank.sqlformatter.languages.Dialect or String to SqlFormatter.of :
SqlFormatter
.of(Dialect.N1ql) // Recommended
//.of("n1ql") // String can be passed
.format("SELECT *");
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
Extend formatters
Formatters can be extended as below :
SqlFormatter
.of(Dialect.MySql)
.extend(cfg -> cfg.plusOperators("=>"))
.format("SELECT * FROM table WHERE A => 4")
Then it results in:
SELECT
*
FROM
table
WHERE
A => 4
Placeholders replacement
You can pass List or Map to format :
// Named placeholders
Map<String, String> namedParams = new HashMap<>();
namedParams.put("foo", "'bar'");
SqlFormatter.of(Dialect.TSql).format("SELECT * FROM tbl WHERE foo = @foo", namedParams);
// Indexed placeholders
SqlFormatter.format("SELECT * FROM tbl WHERE foo = ?", Arrays.asList("'bar'"));
Both result in:
SELECT
*
FROM
tbl
WHERE
foo = 'bar'
Build
Building this library requires JDK 11 because of ktfmt.
Explorar proyectos relacionados
Asabeneh/30-Days-Of-Python
El reto de programación 30 Days of Python es una guía paso a paso para aprender el lenguaje de programación Python en 30 días. Este reto puede llevar más de 100 días. Sigue tu propio ritmo. Estos vídeos también pueden ayudarte: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,711 estrellasgrafana/grafana
Plataforma abierta y componible de observabilidad y visualización de datos. Visualiza métricas, registros y trazas de múltiples fuentes, como Prometheus, Loki, Elasticsearch, InfluxDB, Postgres y muchas más.
77,894 estrellasredis/redis
Para los desarrolladores que crean aplicaciones en tiempo real basadas en datos, Redis es la opción preferida, la más rápida y la de más funciones como caché, servidor de estructuras de datos y motor de consultas de documentos y vectores.
77,490 estrellasapache/superset
Apache Superset es una plataforma de visualización y exploración de datos.
75,522 estrellas