sql_formatter 0.1.0
sql_formatter: ^0.1.0 copied to clipboard
A pure-Dart SQL pretty-printer supporting standard SQL, PostgreSQL, MySQL and SQLite dialects. A faithful port of the JS sql-formatter library.
Changelog #
0.1.0 #
Initial release.
- Pure-Dart, dependency-free SQL pretty-printer — a port of the JS
sql-formatter. - Dialects: standard SQL, PostgreSQL, MySQL/MariaDB, SQLite.
format(sql, {dialect, options})withFormatOptions(indent,keywordCase,linesBetweenQueries).- Deterministic and idempotent output; best-effort handling of malformed SQL (no throws).
BETWEEN x AND ykeeps its innerANDinline; laterANDs still break the line.- Data-type keywords are uppercased (under
keywordCase.upper) insideCAST(... AS type)and::typecasts as well asCREATE TABLEcolumn lists. - Linear-time output path (no per-token whole-buffer scanning), so formatting stays fast on very large inputs.
- Unary
-/+attach to their operand (-1,LIMIT -1,a * -1) instead of being spaced like a binary operator. - PostgreSQL array literals and subscripts render tight and inline:
ARRAY[1, 2, 3],tags[1],TEXT[]. - DDL keywords keep their object on the same line:
ALTER TABLE t …,CREATE INDEX …,CREATE VIEW …,DROP TABLE …. MERGE … WHEN MATCHED … WHEN NOT MATCHED …is laid out as structured clauses (best-effort).- Dollar-quoted strings (
$$…$$,$tag$…$tag$) are preserved verbatim in every dialect.