CST-based SQL formatter following sqlstyle.guide conventions.
This crate provides SQL formatting that preserves the structure of the original code while applying consistent style rules.
Stability
Pre-1.0. The intended public surface is the format / format_sqlstyle /
format_with_pgformatter entry points, the edit helpers (format_edits,
format_range, diff_edits, TextEdit) and the config types
(FormatConfig, PgFormatterConfig, …). Printer internals may change
without a semver bump.
Features
- River alignment for keyword alignment
- Configurable keyword case (UPPER, lower, Preserve)
- Leading or trailing comma style
- Proper indentation for subqueries and CTEs
- Comment preservation
- Error node preservation (malformed SQL preserved as-is)
Usage
use banshee_format::{format, FormatConfig};
let sql = "select id,name from users where active=true";
let formatted = format(sql, &FormatConfig::sqlstyle());
println!("{}", formatted);
// Output:
// SELECT id
// , name
// FROM users
// WHERE active = TRUE