Formatting options

syntaqlite's formatter has four configuration options. All have sensible defaults; you can use syntaqlite fmt with no flags and get well-formatted SQL. Every option is available across the CLI, Rust, C, and JavaScript APIs.

Options can also be set in syntaqlite.toml. CLI flags override config file values.

Options

OptionCLI flagConfig file keyDefaultDescription
Line width-w, --line-width <N>line-width80Target maximum line width (characters)
Indent width-t, --indent-width <N>indent-width2Spaces per indentation level
Keyword case-k, --keyword-case <CASE>keyword-caseupperupper or lower
Semicolons--semicolons <BOOL>semicolonstrueAppend ; after each statement

Line width

Controls when the formatter breaks a statement across multiple lines. The formatter tries to fit as much as possible within this width, breaking at natural points (before clauses, between list items) when the line would be too long.

# Narrow: breaks more aggressively
echo "SELECT id, name, email, created_at FROM users WHERE active = 1" \
  | syntaqlite fmt -w 40
SELECT id, name, email, created_at
FROM users
WHERE
  active = 1;
# Wide: keeps more on one line
echo "SELECT id, name, email, created_at FROM users WHERE active = 1" \
  | syntaqlite fmt -w 120
SELECT id, name, email, created_at FROM users WHERE active = 1;

The line width is a target, not a hard limit. The formatter won't break a single long identifier or string literal to stay within the width.

Indent width

The number of spaces used for each indentation level (e.g., continuation of WHERE conditions, subqueries, column lists that break across lines).

echo "SELECT id, name FROM users WHERE active = 1 AND role = 'admin'" \
  | syntaqlite fmt -t 4

Keyword case

Controls whether SQL keywords are uppercased or lowercased. Identifiers, string literals, and other non-keyword tokens are never modified.

echo "Select Id From Users Where Active = true" | syntaqlite fmt -k upper
SELECT Id FROM Users WHERE Active = true;
echo "Select Id From Users Where Active = true" | syntaqlite fmt -k lower
select Id from Users where Active = true;

Semicolons

Controls whether a semicolon is appended after each statement.

echo "SELECT 1" | syntaqlite fmt --semicolons=true
SELECT 1;
echo "SELECT 1" | syntaqlite fmt --semicolons=false
SELECT 1

API usage

These options are available in all embedding APIs: