Command line
Reesql reads SQL from stdin or a file and writes back consistently formatted SQL. It is designed to drop into pipes, editor commands, and pre-commit hooks.
Format a file in place
Pass a path and Reesql formats that file in place:
reesql path/to/file.sql
Format from stdin
With no file argument, Reesql reads from stdin and writes the result to stdout:
cat query.sql | reesql
Pipe directly
echo "SELECT * FROM users WHERE active = 1;" | reesql
Options
| Flag | Description |
|---|---|
--version, -v | Print the bare version number and exit. |
--where | Print the directory the binary lives in and exit. |
Editor and hook integration
Because Reesql is a plain stdin/stdout filter, it plugs into most editors as an external formatter and into Git as a pre-commit step. For example, to format and fail CI if anything changed:
reesql schema.sql
git diff --exit-code
What Reesql does
- Uppercases keywords -
SELECT,FROM,WHERE,CREATE,INSERT, and the rest. - Aligns definitions -
CREATE TABLEcolumns and types line up;CREATE VIEWselect columns align onAS. - Structures statements -
UPDATEputs eachSETassignment on its own line;WHEREclauses move to their own line; longINSERTvalue tuples wrap. - Indents subqueries -
(SELECT ...)subqueries are formatted recursively. - Preserves comments -
--,/* */, and#comments are kept and repositioned. - Normalises line endings -
\r\nand\nare handled consistently.
For the full list of statement types see Supported statements, and for before/after samples see Examples.